回答編集履歴
1
追記
test
CHANGED
@@ -37,3 +37,49 @@
|
|
37
37
|
//res:1.1666666666666667
|
38
38
|
|
39
39
|
```
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
追記
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
> kotlinに変換しましたが、問題が数点発生しています
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
```kotlin
|
52
|
+
|
53
|
+
import javax.script.ScriptEngineManager
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
object xxScriptK {
|
58
|
+
|
59
|
+
@JvmStatic
|
60
|
+
|
61
|
+
fun main(args: Array<String>) {
|
62
|
+
|
63
|
+
val scriptEngineManager = ScriptEngineManager()
|
64
|
+
|
65
|
+
val scriptEngine = scriptEngineManager.getEngineByName("javascript")
|
66
|
+
|
67
|
+
val str1 = "(1+2.5)/3"
|
68
|
+
|
69
|
+
val res = scriptEngine.eval(str1)
|
70
|
+
|
71
|
+
println("res:${res::class}")
|
72
|
+
|
73
|
+
println("res:$res")
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
//Warning: Nashorn engine is planned to be removed from a future JDK release
|
80
|
+
|
81
|
+
//res:class kotlin.Double
|
82
|
+
|
83
|
+
//res:1.1666666666666667
|
84
|
+
|
85
|
+
```
|