Kotlin 中文文档
来源:互联网 发布:php单引号转义函数 编辑:程序博客网 时间:2024/06/05 19:21
转载地址:http://www.tuicool.com/articles/faqyMzE
gitbook 墙内访问速度很糟糕 现在有了 墙内地址 啦 :)
国内服务器由 掘金 赞助
稀土掘金:挖掘最优质的互联网技术 / 联合编辑每日精选内容 / 移动端优质阅读体验
本书源码在github
pd下载 ePub下载
记得要点 star star star
发现有翻译的不好的或者错误欢迎到 github 提issue
号外 号外 Kotlin 1.0 正式发布
Android 世界的 Swift 终于发布1.0版本
Kotlin 是一个实用性很强的语言,专注于互通,安全,简洁,工具健全...
无缝支持 Java+Kotlin 项目,可以更少的使用样版代码,确保类型安全。
Kotlin 1.0 更新日志
还换了logo :)
Kotlin LOC (软件规模代码行) 如下图
近期我会重新读一遍 Kotlin 官方文档 并对现在的这份文档进行更新(又立 flag 了) -- 2016.2.16
准备开始
- 基本语法
- 习惯用语
- 编码风格
基础
- 基本类型
- 包
- 控制流
- 返回与跳转
类和对象
- 类和继承
- 属性和字段
- 接口
- 可见性修饰词
- 扩展
- 数据对象
- 泛型
- 嵌套类
- 枚举类
- 对象表达式和声明
- 代理模式
- 代理属性
函数和lambda表达式
- 函数
- 高级函数和lambda表达式
- 内联函数
其它
- 多重申明
- Ranges
- 类型检查和自动转换
- This表达式
- 等式
- 运算符重载
- 空安全
- 异常
- 注解
- 反射
- 动态类型
参考
- API
- 语法
互用性
- 与 java 交互
工具
- Kotlin代码文档
- 使用Maven
- 使用Ant
- 使用Griffon
- 使用Gradle
FAQ
- 与java对比
- 与Scala对比
如何在Android studio中使用KotLin
在根目录build.gradle里边添加相应的依赖就好
看示例:
添加了版本号以及要使用的俩个依赖,如果需要还可以导入其他的依赖。
在app的目录(也就是你android代码目录)的build.gradle文件中添加简单的设置就好
看示例:
主要添加了有3个地方:
1、
2、
3、
这样就可以正常使用了。
如果出现
Execution failed for task ':app:clean'.
> Unable to delete file: C:\Users\User\KotlinGameEngine\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\23.0.1\jars\classes.jar
类似这样的问题,那么只要在app目录下的build.gradle文件中添加task:
如果出现Unresolved reference: kotlinx这样的问题,那么需要在app目录下的build.gradle文件中添加:
apply plugin: 'kotlin-android-extensions'
以及要确保classpath配置了classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
看示例:
// Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript { ext.kotlin_version = '1.0.6' repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.0.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" }}allprojects { repositories { jcenter() }
添加了版本号以及要使用的俩个依赖,如果需要还可以导入其他的依赖。
在app的目录(也就是你android代码目录)的build.gradle文件中添加简单的设置就好
看示例:
buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.0.0' }}def getDate() { return Calendar.getInstance().getTimeInMillis();}allprojects { repositories { jcenter() }}apply plugin: 'com.android.application'apply plugin: 'kotlin-android'dependencies { compile 'com.android.support:support-v4:23.1.1' compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:design:23.1.1' compile 'com.android.support:preference-v7:23.1.1' compile 'org.apache.commons:commons-compress:1.10' compile 'commons-net:commons-net:3.3' compile 'com.github.zafarkhaja:java-semver:0.9.0' compile 'org.unbescape:unbescape:1.1.1.RELEASE' compile 'org.msgpack:msgpack:0.6.12' compile 'com.googlecode.juniversalchardet:juniversalchardet:1.0.3' compile 'org.tukaani:xz:1.5' compile 'ch.acra:acra:4.6.2' testCompile 'junit:junit:4.12' compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"}android { compileSdkVersion 23 buildToolsVersion '23.0.2' compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } packagingOptions { exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE.txt' } defaultConfig { minSdkVersion 9 targetSdkVersion 22 versionCode 4 versionName "1.7.0-unstable" if(System.getenv("NIGHTLY_BUILD")) { versionName += "+" + System.getenv("NIGHTLY_BUILD_COMMIT").substring(0, 7) } } lintOptions { if (System.getenv("NIGHTLY_BUILD")) { checkReleaseBuilds false } abortOnError false } signingConfigs { release { if (System.getenv("KEYSTORE_FILE") != null) { storeFile = file(System.getenv("KEYSTORE_FILE")) storePassword = System.getenv("KEYSTORE_PWD") keyAlias = System.getenv("KEYSTORE_ALIAS") keyPassword = System.getenv("KEYSTORE_ALIAS_PWD") } return true } } buildTypes { debug { buildConfigField "java.util.Date", "BUILD_TIME", "new java.util.Date(" + getDate() + "L)" buildConfigField "String", "BUILD_NAME", "\"" + System.getenv("USER") + "\""; minifyEnabled false shrinkResources false debuggable true jniDebuggable true zipAlignEnabled true multiDexEnabled true } release { buildConfigField "java.util.Date", "BUILD_TIME", "new java.util.Date(" + getDate() + "L)" buildConfigField "String", "BUILD_NAME", "\"" + System.getenv("USER") + "\""; if (System.getenv("KEYSTORE_FILE") != null) { signingConfig signingConfigs.release } multiDexEnabled true return true } } sourceSets { main.java.srcDirs += 'src/main/kotlin' }}repositories { mavenCentral()}
主要添加了有3个地方:
1、
apply plugin: 'kotlin-android'
2、
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
3、
android{ ......sourceSets {main.java.srcDirs += 'src/main/kotlin'}}
这样就可以正常使用了。
如果出现
Execution failed for task ':app:clean'.
> Unable to delete file: C:\Users\User\KotlinGameEngine\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\23.0.1\jars\classes.jar
类似这样的问题,那么只要在app目录下的build.gradle文件中添加task:
task clean(type: Exec) { ext.lockhunter = '\"C:\\LockHunter.exe\"' def buildDir = file(new File("build")) commandLine 'cmd', "$lockhunter", '/delete', '/silent', buildDir}
如果出现Unresolved reference: kotlinx这样的问题,那么需要在app目录下的build.gradle文件中添加:
apply plugin: 'kotlin-android-extensions'
以及要确保classpath配置了classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
0 1
- Kotlin的中文文档
- Kotlin 中文文档
- kotlin中文开发文档
- Android的swift语言Kotlin中文开发文档
- kotlin-中文免费文档(后台,android,前端)
- Kotlin习惯用语和编码风格[转自Kotlin中文文档]
- Kotlin学习总结文档
- Kotlin学习总结文档
- Kotlin语言文档翻译项目
- 开发文档之Kotlin语言
- kotlin官方文档-1.0入门
- kotlin官方文档-2.1基础
- kotlin官方文档-2.2包
- Kotlin基本语法文档记录
- Kotlin 中文学习资料集锦
- kotlin基本语法--kotlin官网文档学习
- kotlin习惯用法——kotlin官方文档学习
- Kotlin编码规范和基本类型--kotlin官方文档学习
- 什么是敏捷软件测试
- 二叉树
- ContentProvider与ContentResolver的交互(应用之间的数据交换)(未完)
- 计算出你来到这个世界多少天
- 昨日总结说明
- Kotlin 中文文档
- 标准仿C语言 memset、memcpy、memmove函数(含C#版)
- DDraw应用样例
- Mysql分库分表方案
- COM---动态链接
- KMP —— next数组
- React学习资源汇总
- 安卓网络Httpuilconnection和handler助手
- walle项目配置出现问题