Last active
April 8, 2017 03:15
-
-
Save kodaitakahashi/e5fc1545ae1febd9a23bbdabdd601e81 to your computer and use it in GitHub Desktop.
ジェネリックスを用いたインターフェースの継承の問題
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
interface GenInterface<T> { | |
void showState(T t); | |
} | |
interface GenInterface2<T> extends GenInterface<String> { | |
void dispState(T t); | |
} | |
---------------------------------------------------------------- | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.List; | |
class Gene<T> implements GenInterface<Integer>, GenInterface2<Integer> { | |
private T val1; | |
public Gene(T val1) { | |
this.val1 = val1; | |
} | |
public Class<?> getKlass() { | |
return val1.getClass(); | |
} | |
@Override | |
public void dispState(Integer t) { | |
System.out.println(t); | |
} | |
@Override | |
public void showState(Integer t) { | |
System.out.println(t); | |
} | |
} | |
public class Gen2 { | |
public static void main(String[] args) { | |
Gene<Integer> gen1 = new Gene<>(1); | |
gen1.showState(100); | |
gen1.dispState(200); | |
} | |
} | |
/* | |
* 1 コンパイルが通って無事実行もできる | |
* 2 実行時43行目でエラーが起こる | |
* 3 実行時44行目でエラーが起こる | |
* 4 コンパイルエラーが起こる | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment