kotlin笔记

类的继承以及接口实现都需要使用:

例如

class WIGLSurfaceView : GLSurfaceView 

class WLRender : GLSurfaceView.Renderer 

构造方法需要使用contructor关键字
class WLRender : GLSurfaceView.Renderer {
constructor(context: Context) {
this.context = context
vertexBuffer = ByteBuffer.allocateDirect(vertexData.size * 4).order(ByteOrder.nativeOrder()).asFloatBuffer()
.put(vertexData);
vertexBuffer.position(0)
}
}


不需要使用switch,使用when以及lamda表达式

while循环替换使用方法
java
while((line = reader.readLine()) != null)
{
sb.append(line).append(" ");
}
kotlin
do {
line = reader.readLine()
if (line == null) {
break
}
sb.append(line).append(" ")
} while (true)

int以及float数组不使用[],而是使用相关的类
var lineStatus = IntArray(1)
val vertexData: FloatArray = floatArrayOf(-1f, 0f, 0f, 1f, 1f, 0f)




原文地址:https://www.cnblogs.com/dongweiq/p/10974286.html