草庐IT

Kotlin-script

全部标签

casting - 在 Kotlin 中可以进行交叉转换吗?

我在Java中有这样的方法:publicmethodName(Targ,...)其中A是一个类,B是一个接口(interface)。在我的kotlin类中,我有另一个C类型的variable,我希望实现以下目标:if(variableisA&&variableisB){methodName(variable,...)}else{//dosomethingelse}是否可以正确地转换variable以便它可以用作参数而不会出错?Currently,thevariablehasasettermethod,sosmartcastingisn'tavailable.However,Ihavea

kotlin - Kotlin 中的构建器模式

我是kotlin世界的新手。我有一个用Java编写的现有构建器,并希望在将项目迁移到Android中的kotlin时将其转换为Kotlin。但是,AndroidStudio内置工具似乎有一些错误,则转换后的代码无法编译。它显示我的UserBuilder类中的变量无法访问。这是来自tutorial的Java代码publicclassPerson{privatefinalStringfirstName;//requiredprivatefinalStringlastName;//requiredprivatefinalintage;//optionalprivatefinalStringp

kotlin - Kotlin 中的构建器模式

我是kotlin世界的新手。我有一个用Java编写的现有构建器,并希望在将项目迁移到Android中的kotlin时将其转换为Kotlin。但是,AndroidStudio内置工具似乎有一些错误,则转换后的代码无法编译。它显示我的UserBuilder类中的变量无法访问。这是来自tutorial的Java代码publicclassPerson{privatefinalStringfirstName;//requiredprivatefinalStringlastName;//requiredprivatefinalintage;//optionalprivatefinalStringp

kotlin - runBlocking 中有两个以上等待

我在Kotlin中的await有问题,如果我只使用2个awaits,这个runBlockingblock可以工作10秒,但是当我尝试使用4个awaits,它工作20秒。据我了解,runBlocking中只有两个异步线程。如何增加此计数?funtestFun(){valz1=async{Thread.sleep(10000)}valz2=async{Thread.sleep(10000)}valz3=async{Thread.sleep(10000)}valz4=async{Thread.sleep(10000)}runBlocking{z1.await()z2.await()z3.aw

kotlin - runBlocking 中有两个以上等待

我在Kotlin中的await有问题,如果我只使用2个awaits,这个runBlockingblock可以工作10秒,但是当我尝试使用4个awaits,它工作20秒。据我了解,runBlocking中只有两个异步线程。如何增加此计数?funtestFun(){valz1=async{Thread.sleep(10000)}valz2=async{Thread.sleep(10000)}valz3=async{Thread.sleep(10000)}valz4=async{Thread.sleep(10000)}runBlocking{z1.await()z2.await()z3.aw

junit - NotAMockException/如何在 Kotlin 的参数化测试中 stub 值?

对于以下Kotlin类:classProductLogic(privatevalproduct:Product?){funshouldShow():Boolean{if(product==null){returnfalse}valversion=product.version!!if(!Utils.isAtLeastVersionX(version.major,version.minor)){returnfalse}returntrue}}我正在尝试在Kotlin中编写参数化测试:@RunWith(ParameterizedRobolectricTestRunner::class)@C

junit - NotAMockException/如何在 Kotlin 的参数化测试中 stub 值?

对于以下Kotlin类:classProductLogic(privatevalproduct:Product?){funshouldShow():Boolean{if(product==null){returnfalse}valversion=product.version!!if(!Utils.isAtLeastVersionX(version.major,version.minor)){returnfalse}returntrue}}我正在尝试在Kotlin中编写参数化测试:@RunWith(ParameterizedRobolectricTestRunner::class)@C

android - kotlin android proguard错误

我正在尝试构建一个apk并对其进行保护,但它失败并显示如下消息:Error:ProGuard:[radis]Warning:kotlin.dom.EventListenerHandler:can'tfindsuperclassorinterfaceorg.w3c.dom.events.EventListenerError:ProGuard:[radis]Warning:kotlin.dom.CloseableEventListener:can'tfindreferencedclassorg.w3c.dom.events.EventTargetError:ProGuard:[radis]

android - kotlin android proguard错误

我正在尝试构建一个apk并对其进行保护,但它失败并显示如下消息:Error:ProGuard:[radis]Warning:kotlin.dom.EventListenerHandler:can'tfindsuperclassorinterfaceorg.w3c.dom.events.EventListenerError:ProGuard:[radis]Warning:kotlin.dom.CloseableEventListener:can'tfindreferencedclassorg.w3c.dom.events.EventTargetError:ProGuard:[radis]

android - Kotlin:我们可以在 Kotlin 中使用 EventBus (GreenRobot) 的 @Subscribe 吗?

我的onEvent在下面的fragment中,在我的Kotlin函数中捕获Activity的身份验证。但是,我无法触发onEvent。@SubscribefunonEvent(event:AuthenticationEvent){if(event.isAuthenticated){startFragment(signInFragment,SignInFragment.TAG)}else{startFragment(signOutFragment,SignOutFragment.TAG)}}在我的build.gradle文件中,我添加了这个compile'org.greenrobot:e