标签:
// 编译成 java-int-list_1.0.jar
public final class JavaIntList {
static class Node {
public Node next;
public int value;
}
public Node head;
public int size;
}
JavaIntList myList = new JavaIntList();
System.out.println(myList.size);
// 编译成 java-int-list_2.0.jar
public final class JavaIntList {
static final class Node {
public Node next;
public int value;
}
public Node head;
public int getSize() {
Node n = head;
int i = 0;
while (n != null) {
n = n.next;
i++;
}
return i;
}
}
private int size;
public int getSize() { return size; }
// 编译成 scala-int-list_1.0.jar
object ScalaIntList {
final case class Node(next: Node, value: Int)
}
final class ScalaIntList {
var head: ScalaIntList.Node = null
var size: Int = 0
}
val myList = new ScalaIntList
println(myList.size)
// 编译成 scala-int-list_2.0.jar
object ScalaIntList {
final case class Node(next: Node, value: Int)
}
final class ScalaIntList {
var head: ScalaIntList.Node = null
final def size: Int = {
var n = head
var i = 0
while (n != null) {
n = n.next
i++
}
i
}
}
标签:
原文地址:http://www.cnblogs.com/blog4matto/p/5584886.html