SHARE
TWEET

abstract

DulcetAirman Jul 28th, 2018 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ch.claude_martin;
  2.  
  3. import java.lang.reflect.Modifier;
  4.  
  5. public class SomeClass {
  6.  
  7.   static abstract class MyAbstractClass {
  8.     @Override
  9.     public String toString() {
  10.       return "Hello!";
  11.     }
  12.   }
  13.  
  14.   static interface MyInterface {
  15.     default int foo() {
  16.       return 42;
  17.     }
  18.   }
  19.  
  20.   public static void main(String[] args) throws Throwable {
  21.  
  22.     MyAbstractClass instance = new MyAbstractClass() {
  23.     };
  24.  
  25.     System.out.println(instance);
  26.  
  27.     int modifiers = MyInterface.class.getMethod("foo").getModifiers();
  28.     boolean isAbstract = Modifier.isAbstract(modifiers);
  29.     if (isAbstract)
  30.       System.out.println("foo is abstract");
  31.     else
  32.       System.out.println("foo is not abstract");
  33.  
  34.   }
  35. }
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