Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ImmutableList;
- import com.sun.org.apache.bcel.internal.classfile.ClassFormatException;
- import java.lang.reflect.Field;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.stream.Collectors;
- public class Main {
- public static void main(String[] args) throws ClassFormatException{
- Field[] fields = ImmutableList.class.getDeclaredFields();
- if (fields.length < 1) {
- throw new ClassFormatException();
- }
- java.lang.reflect.Method[] methods = ImmutableList.class.getDeclaredMethods();
- List<java.lang.reflect.Method> methodsReturnTypes = Arrays.stream(methods).filter(m -> {
- if (!m.getReturnType().getName().equalsIgnoreCase("ImmutableList")) {
- return false;
- }
- return true;
- }).collect(Collectors.toList());
- if (methodsReturnTypes.size() < 1) {
- throw new ClassFormatException();
- }
- }
- }
- class ImmutableList{
- List<Integer> collection;
- public ImmutableList(List<Integer> collection) {
- this.collection = new ArrayList<>();
- }
- public ImmutableList getCollection(){
- return new ImmutableList(this.collection);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement