我想知道在Kotlin中变量名之前asterisk究竟是做什么的.我*args在Spring boot Kotlin上看到了这个():
@SpringBootApplication
open class Application {
@Bean
open fun init(repository: CustomerRepository) = CommandLineRunner {
repository.save(Customer("Jack", "Bauer"))
repository.save(Customer("Chloe", "O'Brian"))
repository.save(Customer("Kim", "Bauer"))
repository.save(Customer("David", "Palmer"))
repository.save(Customer("Michelle", "Dessler"))
}
}
fun main(args: Array<String>) {
SpringApplication.run(Application::class.java, *args)
}
Run Code Online (Sandbox Code Playgroud) 我想RestTemplate在Kotlin中使用Spring ,如下所示:
//import org.springframework.web.client.RestTemplate
fun findAllUsers(): List<User> {
val restTemplate = RestTemplate()
//has error
val ret = List<User>.javaClass
return restTemplate.getForObject(URI(hostAddress), ret)
}
Run Code Online (Sandbox Code Playgroud)
该RestTemplate.getForObject(URI url, Class<T> responseType)有这个签名,我从得到这个错误"未解决的参考序列" List在val ret = List<User>.javaClass.
如果我这样使用,val ret = List<User>::class.java我会收到此错误"只允许类在类文字的左侧"
有什么问题?这样做的正确方法是什么?这是一个错误吗?
我是tornadoFX的新手,我不知道如何设置PrimaryStage或Scene属性,如场景高度或宽度或PrimaryStage模态.请帮我.
UPDATE
我想设置场景高度和宽度,看看这个例子:
dependencies {
compile 'no.tornado:tornadofx:1.5.2'
compile "org.jetbrains.kotlin:kotlin-stdlib:1.0.3"
}
Run Code Online (Sandbox Code Playgroud)
import javafx.scene.control.Label
import javafx.scene.layout.VBox
import tornadofx.App
import tornadofx.FX
import tornadofx.View
class Main : App() {
override val primaryView = MyView::class
init {
// this two lines have error ( Val cannot be reassigned. )
FX.primaryStage.scene.height = 600.0
FX.primaryStage.scene.width = 800.0
// or this line causes this exception ( java.lang.NoSuchMethodException )
FX.primaryStage.isResizable = false
}
}
class MyView : View() {
override val root = VBox()
init {
root.children.add(Label("My label"))
} …Run Code Online (Sandbox Code Playgroud) 我想用Java脚本运行kotlin代码作为脚本,Java脚本API类似于javascript:
import javax.script.*;
public class EvalScript {
public static void main(String[] args) throws Exception {
// create a script engine manager
ScriptEngineManager factory = new ScriptEngineManager();
// create a JavaScript engine
ScriptEngine engine = factory.getEngineByName("JavaScript");
// evaluate JavaScript code from String
engine.eval("print('Hello, World')");
}
}
Run Code Online (Sandbox Code Playgroud)
或者像这样的类似API.
我编写了这个代码,它不止一次地借用一个可变变量并且编译时没有任何错误,但是根据The Rust Programming Language,这不应该编译:
fn main() {
let mut s = String::from("hello");
println!("{}", s);
test_three(&mut s);
println!("{}", s);
test_three(&mut s);
println!("{}", s);
}
fn test_three(st: &mut String) {
st.push('f');
}
Run Code Online (Sandbox Code Playgroud)
(游乐场)
这是一个错误还是Rust中有新功能?
我最近按照本指南创建了一个Angular Material 2应用程序.现在我想知道如何将主题更改为黑暗或dark-theme?