daily pastebin goal
2%
SHARE
TWEET

InstanceofTest.java

RandomGuy32 May 31st, 2015 243 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class InstanceofTest {
  2.         public static void main(String[] args) {
  3.                 Something someObject = new Something();
  4.                 InstanceofTest.doSomething(someObject);
  5.         }
  6.         public static void doSomething(SomeInterface s) {
  7.                 s.method1();
  8.                 if (s instanceof SomeOtherInterface) {
  9.                         s.method2();
  10.                 }
  11.         }
  12. }
  13.  
  14. class Something implements SomeInterface {
  15.         public Something() {}
  16.        
  17.         public void method1() {}
  18. }
  19. class SomethingElse implements SomeInterface, SomeOtherInterface {
  20.         public SomethingElse() {}
  21.        
  22.         public void method1() {}
  23.         public void method2() {}
  24. }
  25. interface SomeInterface {
  26.         public void method1();
  27. }
  28. interface SomeOtherInterface {
  29.         public void method2();
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top