鉴于以下Kotlin类:
data class Test(val value: Int)
Run Code Online (Sandbox Code Playgroud)
Int如果值为负,我将如何覆盖getter以使其返回0?
如果这是不可能的,那么有哪些技术可以获得合适的结果呢?
自从升级到最新的appcompat库以来,我在ViewUtils的日志中看到了一条消息.
app:theme is now deprecated. Please move to using android:theme instead.
我parent="Theme.AppCompat.Light.NoActionBar"用作我的主题父母.
我正在使用Retrofit来做一个基本的POST请求,我正在为请求提供一个基本的@Body.
@POST("/rest/v1/auth/login")
LoginResponse login(@Body LoginRequest loginRequest);
Run Code Online (Sandbox Code Playgroud)
当我为Retrofit构建界面时,我正在提供我自己的自定义OkHttpClient,而我正在做的就是添加我自己的自定义身份验证:
@Provides
@Singleton
public Client providesClient() {
OkHttpClient httpClient = new OkHttpClient();
httpClient.setAuthenticator(new OkAuthenticator() {
@Override
public Credential authenticate(Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
return getCredential();
}
@Override
public Credential authenticateProxy(Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
return getCredential();
}
});
return new OkClient(httpClient);
}
Run Code Online (Sandbox Code Playgroud)
当我使用OKHttp直接发送请求时,以及其他GET请求进行改造,但是当我使用改造来执行POST请求时,我会收到以下错误:
Caused by: java.net.HttpRetryException: Cannot retry streamed HTTP body
at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:324)
at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:508)
at com.squareup.okhttp.internal.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:136)
at retrofit.client.UrlConnectionClient.readResponse(UrlConnectionClient.java:94)
at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:49)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:357)
at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:282)
at …Run Code Online (Sandbox Code Playgroud) 因此,有人将用于Java 8的Lambdas反向回Java 6和7.显然它也适用于Android.该项目名为Retrolambda.我想在AndroidStudio上玩这个,但在最近的版本中它们似乎已经删除了将Java 8设置为语言级别的能力(因此我在使用Lambdas时不会遇到编译错误).有没有人知道这方面的方法?我想这与AndroidStudio是一个改进的IntelliJ这一事实有关.任何帮助,将不胜感激.
我正在使用Kotlin gradle插件编译带有Gradle的Kotlin库jar:
apply plugin: 'kotlin'
我正在尝试找到一种方法将简单的-include-runtime编译器参数传递给kotlin编译器.我似乎无法找到任何关于此的文档.我试过模仿java插件,但这似乎没有用.以下是有关使用命令行编译器的一些文档,但gradle文档没有提及有关传递编译器参数的任何信息.
当我使用No.2脚本时,为什么Android Studio显示错误.我发现1和2之间没有区别.
class Adapter {
var nameList : ArrayList<String>? = null
}
class Program {
private fun send() {
val list: ArrayList<String> = ArrayList()
val adapter = Adapter()
// Case 1
var otherList = adapter.nameList
if (otherList != null) {
list.addAll(otherList) // <--- no error
}
// Case 2
if (adapter.nameList!=null) {
list.addAll(adapter.nameList) // <--- Error here
// Smart cast to 'kotlin.collections.ArrayList<String> /* = java.util.ArrayList<String> */' is impossible, because 'adapter.nameList' is a mutable property that could have been changed by …Run Code Online (Sandbox Code Playgroud) 所以我正在玩RX(非常酷),我一直在转换我的api,它访问Android中的sqlite数据库以返回observables.
所以我开始尝试解决的问题之一就是"如果我想要进行3次API调用,得到结果,然后在完成后再进行一些处理,该怎么办?"
我花了一个小时或两个小时,但我最终找到了Zip功能,它帮助我轻松地:
Observable<Integer> one = getNumberedObservable(1);
Observable<Integer> two = getNumberedObservable(2);
Observable<Integer> three = getNumberedObservable(3);
Observable.zip(one, two, three, new Func3<Integer, Integer, Integer, Integer>() {
@Override
public Integer call(Integer arg0, Integer arg1, Integer arg2) {
System.out.println("Zip0: " + arg0);
System.out.println("Zip1: " + arg1);
System.out.println("Zip2: " + arg2);
return arg0 + arg1 + arg2;
}
}).subscribe(new Action1<Integer>() {
@Override
public void call(Integer arg0) {
System.out.println("Zipped Result: " + arg0);
}
});
public static Observable<Integer> getNumberedObservable(final int value) {
return Observable.create(new …Run Code Online (Sandbox Code Playgroud) 如果我有immutableMap: Map<String, Int>并希望将其转换为a mutableMap: MutableMap<String, Int>,那么最好的方法是什么?似乎没有任何方便的方式.
我是PlayFramework的忠实粉丝,但我对SBT/Scala的经验有限.我一直在尝试更多地使用Kotlin,所以我试图让Kotlin在SBT/PlayFramework上运行.
我已经将Kotlin与Gradle Build系统一起使用,但这需要我应用Kotlin Gradle插件.不知道如何做SBT的等效.
这是Play的基本build.sbt.我怎么去添加Kotlin?
name := """KotlinTestServer"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.11.1"
libraryDependencies ++= Seq(
javaJdbc,
javaEbean,
cache,
javaWs
)
Run Code Online (Sandbox Code Playgroud)
我必须添加"org.jetbrains.kotlin" % "kotlin-stdlib" % "0.10.195"为库依赖项,但还有什么?
我有一个有2种口味的Android应用程序:internal而且production,还有2种构建类型:debug和release.
我正在尝试根据风格分配签名配置,根据文档是可行的.我看了之后发现了其他答案,但似乎都没有.所有内容都会编译,但应用程序正在使用本机的本地调试密钥库进行签名.
这是我的gradle文件:
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0.0"
}
signingConfigs {
internal {
storeFile file("../internal.keystore")
storePassword "password"
keyAlias "user"
keyPassword "password"
}
production {
storeFile file("../production.keystore")
storePassword "password"
keyAlias "user"
keyPassword "password"
}
}
productFlavors {
internal {
signingConfig signingConfigs.internal
applicationId 'com.test.test.internal'
}
production {
signingConfig signingConfigs.production
applicationId 'com.test.test'
}
}
buildTypes {
debug {
applicationIdSuffix ".d"
}
release {
minifyEnabled …Run Code Online (Sandbox Code Playgroud)