Java Class check if a List is Unmodifiable List via its name

Description

Java Class check if a List is Unmodifiable List via its name



import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

public class Main {
  public static void main(String[] args) {
    List<Integer> list = new LinkedList<Integer>();
    list.add(1);/* w ww  .jav  a2s .  co m*/
    
    System.out.println(list.getClass());
    
    List<Integer> unmodifiableList = Collections.unmodifiableList(list);
    System.out.println(unmodifiableList.getClass());
    if (unmodifiableList.getClass().getName().contains("Unmodifiable"))
      System.out.println(true);
  }
}



PreviousNext

Related