Skip to content

Commit

Permalink
泛型Java、Kotlin对比实现
Browse files Browse the repository at this point in the history
  • Loading branch information
BetterZhang committed Jun 28, 2017
1 parent 55518c2 commit 38ee099
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/com/betterzhang/learnkotlin/java/Wrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.betterzhang.learnkotlin.java;

/**
* Created by IntelliJ IDEA.
* Author : Andrew Zhang
* Email : betterzhang.dev@gmail.com
* Time : 2017/06/28 下午 1:12
* Desc : description
*/
public final class Wrapper<T> {

private T item;

public Wrapper(T item) {
this.item = item;
}

public T getItem() {
return item;
}

public static void main(String[] args) {
Wrapper<String> wrapper = new Wrapper<>("Hello Java");
System.out.println(wrapper.getItem());
}

}
15 changes: 15 additions & 0 deletions src/com/betterzhang/learnkotlin/kotlin/Wrapper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.betterzhang.learnkotlin.kotlin

/**
* Created by IntelliJ IDEA.
* Author : Andrew Zhang
* Email : betterzhang.dev@gmail.com
* Time : 2017/06/28 下午 1:18
* Desc : description
*/
class Wrapper<T>(val item: T)

fun main(args: Array<String>) {
var wrapper = Wrapper("Hello Kotlin")
println(wrapper.item)
}

0 comments on commit 38ee099

Please sign in to comment.