Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class InstanceofTest {
- public static void main(String[] args) {
- Something someObject = new Something();
- InstanceofTest.doSomething(someObject);
- }
- public static void doSomething(SomeInterface s) {
- s.method1();
- if (s instanceof SomeOtherInterface) {
- s.method2();
- }
- }
- }
- class Something implements SomeInterface {
- public Something() {}
- public void method1() {}
- }
- class SomethingElse implements SomeInterface, SomeOtherInterface {
- public SomethingElse() {}
- public void method1() {}
- public void method2() {}
- }
- interface SomeInterface {
- public void method1();
- }
- interface SomeOtherInterface {
- public void method2();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement