diff --git a/examples/src/Generics.jet b/examples/src/Generics.jet new file mode 100644 index 00000000000..3801dfac301 --- /dev/null +++ b/examples/src/Generics.jet @@ -0,0 +1,39 @@ +namespace generics; + +import java.util.* + +class Box(t: T) { + var value = t +} + +fun isIntBox(box: Box): Boolean { + return box is Box; +} + +abstract class Source { + fun nextT() : T +} + +fun demo(strs : Source) { + val objects : Source = strs // This is OK, since T is an out-parameter + // ... +} + +fun singletonList(item: T): List { + val result = ArrayList() + result.add(item) + return result +} + +//fun T.basicToString(): String { +// return typeinfo(this) + "@" + System.identityHashCode(this) +//} + +fun main(args: Array) { + val box: Box = Box(1) + System.out?.println(box.value) + System.out?.println(if (isIntBox(box)) "int" else "not int"); + + val singleString: List = singletonList("foo") + System.out?.println(singleString.get(0)) +} diff --git a/examples/src/JavaInterop.jet b/examples/src/JavaInterop.jet new file mode 100644 index 00000000000..311d2c1233b --- /dev/null +++ b/examples/src/JavaInterop.jet @@ -0,0 +1,9 @@ +namespace JavaInterop + +import java.util.* + +fun main(args: Array) { + val list = ArrayList() + list.add("foo") + System.out?.println(list[0]) +}