Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 26072ca

Browse files
Challenge 57.
Generic type erasure
1 parent b002289 commit 26072ca

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package challenge51_60;
2+
3+
/**
4+
* // TODO: 05/12/2019 erasure explanation
5+
*/
6+
public class Challenge_57 {
7+
8+
static <T> T cast(Object anyPokemon){return (T) anyPokemon;}
9+
10+
public static void main( String[] args ) {
11+
Object charmander = 10;
12+
int pikachu = 10;
13+
Integer wartortle = 10;
14+
15+
Integer newtwo = (Integer)89898989;
16+
17+
Integer pokeball1 = cast(charmander);
18+
Integer pokeball2 = cast(pikachu);
19+
Integer pokeball3 = cast(wartortle);
20+
String pokeball4 = cast(newtwo);
21+
22+
System.out.printf("p1= %d, p2= %d, p3= %d, p4= %s", pokeball1, pokeball2, pokeball3, pokeball4);
23+
}
24+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /