Last active
August 31, 2021 12:04
-
-
Save minte9/3355818fac7c7492c49d40f841afaca0 to your computer and use it in GitHub Desktop.
Java / Collections / Generics - https://www.minte9.com/java/collections-generics-1197
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This code will throw an Exception Error | |
* Correct the error line | |
*/ | |
class App { | |
public static void main(String[] args) { | |
/** | |
* SOLUTION | |
*/ | |
Box<Integer> box = new Box<Integer>(); | |
box.set(10); | |
System.out.println(box.get()); // 10 | |
} | |
static class Box<T> { | |
private T t; | |
public void set(T t) { this.t = t; } | |
public T get() { return t; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment