Created
February 1, 2014 00:58
-
-
Save kompiro/8746402 to your computer and use it in GitHub Desktop.
Overrideしてたらキャストしても親のメソッド呼べるわけじゃない事を確認するテスト
This file contains hidden or 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
package toString; | |
import static org.hamcrest.CoreMatchers.is; | |
import static org.junit.Assert.*; | |
import org.junit.Test; | |
public class ToStringTest { | |
class A { | |
@Override | |
public String toString() { | |
return "A"; | |
} | |
} | |
class B extends A { | |
@Override | |
public String toString() { | |
return "B"; | |
} | |
} | |
@Test | |
public void testOverrideToString() { | |
B b = new B(); | |
assertThat(b.toString(),is("B")); | |
assertThat(((A)b).toString(),is("B")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment