Advertisement
KNikov

ImmutableList

Jun 24th, 2016
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. package ImmutableList;
  2.  
  3. import com.sun.org.apache.bcel.internal.classfile.ClassFormatException;
  4.  
  5. import java.lang.reflect.Field;
  6. import java.util.ArrayList;
  7. import java.util.Arrays;
  8. import java.util.List;
  9. import java.util.stream.Collectors;
  10.  
  11. public class Main {
  12.     public static void main(String[] args) throws ClassFormatException{
  13.         Field[] fields = ImmutableList.class.getDeclaredFields();
  14.         if (fields.length < 1) {
  15.             throw new ClassFormatException();
  16.         }
  17.  
  18.         java.lang.reflect.Method[] methods = ImmutableList.class.getDeclaredMethods();
  19.         List<java.lang.reflect.Method> methodsReturnTypes = Arrays.stream(methods).filter(m -> {
  20.             if (!m.getReturnType().getName().equalsIgnoreCase("ImmutableList")) {
  21.                 return false;
  22.             }
  23.  
  24.             return true;
  25.         }).collect(Collectors.toList());
  26.  
  27.         if (methodsReturnTypes.size() < 1) {
  28.             throw new ClassFormatException();
  29.         }
  30.  
  31.     }
  32. }
  33. class ImmutableList{
  34.     List<Integer> collection;
  35.  
  36.     public ImmutableList(List<Integer> collection) {
  37.         this.collection = new ArrayList<>();
  38.     }
  39.     public ImmutableList getCollection(){
  40.         return new ImmutableList(this.collection);
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement