Kotlin + Dagger 2:Dagger *文件不会生成

我第一次开始使用Kotlin和Dagger 2。 我认为所有东西都和Java一样,但显然不是。 匕首不会为我生成Dagger *文件。 这是我的代码: 组件: @PerActivity @Subcomponent(modules = arrayOf(ApplicationModule::class)) interface ActivityComponent { fun inject(app: OneAccountApplication) } @Singleton @Component(modules = arrayOf(ApplicationModule::class)) interface ApplicationComponent { fun inject(syncService: SyncService) @ApplicationContext fun context(): Context fun application(): Application fun ribotsService(): OneAccountService fun preferencesHelper(): PreferencesHelper fun databaseHelper(): DatabaseHelper fun dataManager(): DataManager } @ConfigPersistent @Component(dependencies = arrayOf(ApplicationComponent::class)) interface ConfigPersistentComponent { […]

将静态变量从Java转换为Kotlin

我试图将下面的代码转换为Kotlin,并仍然有一个由Java使用的类(Foo)。 什么是做这种转换的正确方法? 原始Java: public class Foo { public static final String C_ID = "ID"; public static final String C_NAME = "NAME"; public static final String[] VALUES = {"X", "Y", "Z"}; public static String[] getAll() { return new String[] {C_ID, C_NAME}; } } public class Bar { public void doStuff() { String var1 = Foo.C_ID; String[] […]

与日食弹簧kotlin

我已经试过春季启动springtest,Kotlin日食简单的网络。 对于Java类,它可以进行热部署。 但不适用于Kotlin文件。 pom.xml几乎完全来自http://start.spring.io/,除了添加springloaded。 <build> <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory> <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>springloaded</artifactId> <version>1.2.6.RELEASE</version> </dependency> </dependencies> </plugin> </plugins> </build>

Android Studio 3.0 + Kotlin两个Gradle守护进程

Android Studio 3.0(Beta 7)在使用Java + Kotlin编译产品时是否正常运行2个gradle守护程序? 只是建立一个项目而消耗大量的资源 更新10/27/17我已经更新了Android Studio 3.0,但得到两个Gradle Daemon,我认为其他守护进程是Kotlin编译器,因为它说kotlin-compiler-embedabble-1.1.51.jar 。 但为什么它需要有一个单独的过程…

将Python代码转换为Kotlin

我发现代码生成n个不同的颜色 。 我拿了代码,并从中做了一个课 import colorsys import itertools from fractions import Fraction class DistinctColorsGenerator: def __init__(self): self._bias = lambda x: (math.sqrt(x / 3) / Fraction(2, 3) + Fraction(1, 3)) / Fraction(6, 5) self._gen_rgb = lambda x : colorsys.hsv_to_rgb(*x) self._flatten = itertools.chain.from_iterable self._hsvs = lambda: self._flatten(map(self._hsv, self._fracs())) self._rgbs = lambda: map(self._gen_rgb, self._hsvs()) self._gen_colors = lambda: map(self._gen_color, self._rgbs()) […]

Java Stream with :: new to Kotlin

我试图将以下Spring Security代码从Java转换为Kotlin。 Java的: Collection<? extends GrantedAuthority> authorities = Arrays.stream(claims.get(AUTHORITIES_KEY).toString().split(",")) .map(SimpleGrantedAuthority::new) .collect(Collectors.toList()); 科特林: val authorities = Arrays.stream(claims[AUTHORITIES_KEY].toString().split(",".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()) .map(SimpleGrantedAuthority()) .collect(Collectors.toList<SimpleGrantedAuthority>()) 我在.map(SimpleGrantedAuthority())得到一个类型不匹配错误( Required: Function<in String!, out (???..???)>! 如何正确使用::new关键字将上述Java代码转换为Kotlin?

Kotlin的可派生派生类

我使用Android Parcelable插件从https://github.com/nekocode/android-parcelable-intellij-plugin-kotlin 我用这个定义在一个类上试了一下 class ChessClock : TextView { lateinit var player:String constructor(context: Context) : super(context) constructor(context:Context, p:String, angle:Float) : this(context) { player = p rotation = angle } <snip> } 并将定义更改为 class ChessClock() : TextView, Parcelable { lateinit var player:String constructor(context: Context) : super(context) constructor(context:Context, p:String, angle:Float) : this(context){ player = p rotation = angle […]

Kotlin中无限序列的递归定义

我正在试验Kotlin序列,特别是对于以前的值不是简单计算的更复杂的序列。 我想定义的一个例子是所有素数的序列。 定义下一个素数的简单方法是下一个整数,它不能被序列中任何前面的素数整除。 在Scala中,这可以转换为: def primeStream(s: Stream[Int]): Stream[Int] = s.head #:: primeStream(s.tail filter(_ % s.head != 0)) val primes = primeStream(Stream.from(2)) // first 20 primes primes.take(20).toList 我很难把这个翻译成Kotlin。 在scala中它的工作原理是因为你可以传递函数来返回一个将被懒惰评估的序列,但是我不能在Kotlin中做同样的事情。 在Kotlin我试过了 fun primes(seq: Sequence<Int>):Sequence<Int> = sequenceOf(seq.first()) + primes(seq.drop(1).filter {it % seq.first() != 0}) val primes = primes(sequence(2) {it + 1}) primes.take(20).toList() 但是这显然不起作用,因为函数是直接计算的,并导致无限递归。

通用铸造在Kotlin

我有以下的类和接口: public interface ActivityComponent<T extends Activity> { void inject(T activity); } public interface MyActivityComponent extends ActivityComponent<MyActivity> { } public abstract class DaggerActivity extends Activity { abstract ActivityComponent getComponent(Context context); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ActivityComponent component = getComponent(this); } } public class MyActivity extends DaggerActivity { @Override ActivityComponent getComponent(Context context) { MyActivityComponent component […]

有没有官方的Kotlin风格指南?

我只是开始编程Kotlin,每当我学习一门新的语言时,我尝试从一开始就编写推荐的方法(Sun的Java风格指南,Python的PEP8等)。 Kotlin有没有这样的东西? 我似乎无法在网上找到任何说这种或那种方式的东西。