Tag: 特质

使用包括实施方法的Kotlin特征进行改造

只要没有额外的方法实现,性状​​就可以很好地与Retrofit协同工作。 根据返回类型RetrofitError: TwitchApi.someMethod: HTTP method annotation is required (eg, @GET, @POST, etc.). 或java.lang.IllegalArgumentException: TwitchApi.someMethod: Must have either a return type or Callback as last argument. 被抛出。 有没有一种方法来改造忽略一种方法,没有用retrofit.http.GET / PUT / …注释? public trait SomeApi { GET("/endpoint") public fun getSomething(Query("user") user: String): Observable<SomeResponse> class object { public fun create(): SomeApi { val restAdapter = RestAdapter.Builder().setEndpoint("http://localhost").build() return […]

Kotlin VS Scala:使用主构造函数参数实现方法

在斯卡拉你可以写这样的代码。 trait List[T] { def isEmpty() :Boolean def head() : T def tail() : List[T] } class Cons[T](val head: T, val tail: List[T]) :List[T] { def isEmpty = false } 你不需要覆盖它们已经定义的尾部和头部,但是在Kotlin中,我必须对它进行编码。 interface List<T> { fun isEmpty() :Boolean fun head() : T fun tail() : List<T> } class Cons<T>(val head: T, val tail: List<T>) :List<T> { […]