java.util.Collections.checkedList()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(4.7k)|赞(0)|评价(0)|浏览(177)

本文整理了Java中java.util.Collections.checkedList()方法的一些代码示例,展示了Collections.checkedList()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collections.checkedList()方法的具体详情如下:
包路径:java.util.Collections
类名称:Collections
方法名:checkedList

Collections.checkedList介绍

[英]Returns a dynamically typesafe view of the specified list. Trying to insert an element of the wrong type into this list throws a ClassCastException. At creation time the types in listare not checked for correct type.
[中]返回指定列表的动态类型安全视图。尝试在此列表中插入错误类型的元素会引发ClassCastException。创建时,未检查列表中的类型是否正确。

代码示例

代码示例来源:origin: google/guava

@Override
 public List<String> create(String[] elements) {
  List<String> innerList = new ArrayList<>();
  Collections.addAll(innerList, elements);
  return Collections.checkedList(innerList, String.class);
 }
})

代码示例来源:origin: stackoverflow.com

List<Integer> checkedList = Collections.checkedList(list, Integer.class);

代码示例来源:origin: stackoverflow.com

List<Cat> cats = Collections.checkedList(q.list(), Cat.class);

代码示例来源:origin: stackoverflow.com

@SuppressWarnings("unchecked")
List<SyndEntry> entries = Collections.checkedList(sf.getEntries(), SyndEntry.class);

代码示例来源:origin: wildfly/wildfly

public AttachmentList(final Class<T> valueClass) {
  delegate = Collections.checkedList(new ArrayList<T>(), valueClass);
  this.valueClass = valueClass;
}

代码示例来源:origin: wildfly/wildfly

public AttachmentList(final int initialCapacity, final Class<T> valueClass) {
  delegate = Collections.checkedList(new ArrayList<T>(initialCapacity), valueClass);
  this.valueClass = valueClass;
}

代码示例来源:origin: pmd/pmd

@Override
protected Collection<String> defaultSuppressionAnnotations() {
  return Collections.checkedList(Arrays.asList("java.lang.Override"), String.class);
}

代码示例来源:origin: robovm/robovm

@Override public List<E> subList(int fromIndex, int toIndex) {
  return checkedList(l.subList(fromIndex, toIndex), type);
}

代码示例来源:origin: wildfly/wildfly

public AttachmentList(final Collection<? extends T> c, final Class<T> valueClass) {
  delegate = Collections.checkedList(new ArrayList<T>(c.size()), valueClass);
  delegate.addAll(c);
  this.valueClass = valueClass;
}

代码示例来源:origin: wildfly/wildfly

classes.add(Collections.checkedList(randomAccessList, Void.class).getClass());
classes.add(Collections.checkedList(nonRandomAccessList, Void.class).getClass());
classes.add(Collections.checkedMap(Collections.emptyMap(), Void.class, Void.class).getClass());
classes.add(Collections.checkedNavigableMap(Collections.emptyNavigableMap(), Void.class, Void.class).getClass());

代码示例来源:origin: protostuff/protostuff

checkedSet = Collections.checkedSet(es, Size.class);
checkedSortedSet = Collections.checkedSortedSet(ts, String.class);
checkedList = Collections.checkedList(ll, String.class);
checkedRandomAccessList = Collections.checkedList(newList("nine"),
    String.class);

代码示例来源:origin: stackoverflow.com

List<Integer> checked = Collections.checkedList(list, Integer.class);

代码示例来源:origin: stackoverflow.com

Collections.checkedList(
  new ArrayList<String>(uncertainList.size()), String.class)
  .addAll(uncertainList);

代码示例来源:origin: stackoverflow.com

<T extends Super> List<T> myMethod(final Class<T> clazz) {
  final List<T> ret = Collections.checkedList(new ArrayList<T>(), clazz);
  // ... add elements to ret ...
  return ret;
}

代码示例来源:origin: stackoverflow.com

public <T extends Resource> List<T> getResources(Class<T> resourceType, String path)
{
  ResourcesResponse rgRes = new ObjectMapper()
  .readValue(response.body().byteStream(), ResourcesResponse.class)

  return Collections.checkedList(rgRes.resources, resourceType);
}

代码示例来源:origin: com.google.guava/guava-testlib

@Override
 public List<String> create(String[] elements) {
  List<String> innerList = new ArrayList<>();
  Collections.addAll(innerList, elements);
  return Collections.checkedList(innerList, String.class);
 }
})

代码示例来源:origin: stackoverflow.com

class Test<T> {
  List<T> l;

  public Test(Class<T> c) {
    l = Collections.checkedList(new ArrayList<T>(), c);
  }

  public void add(Object o) {
    l.add((T) o);
  }
}

代码示例来源:origin: io.undertow/undertow-core

public AttachmentList(final Collection<? extends T> c, final Class<T> valueClass) {
  delegate = Collections.checkedList(new ArrayList<T>(c.size()), valueClass);
  delegate.addAll(c);
  this.valueClass = valueClass;
}

代码示例来源:origin: org.wildfly.core/wildfly-server

public AttachmentList(final Collection<? extends T> c, final Class<T> valueClass) {
  delegate = Collections.checkedList(new ArrayList<T>(c.size()), valueClass);
  delegate.addAll(c);
  this.valueClass = valueClass;
}

代码示例来源:origin: org.jboss.as/jboss-as-server

public AttachmentList(final Collection<? extends T> c, final Class<T> valueClass) {
  delegate = Collections.checkedList(new ArrayList<T>(c.size()), valueClass);
  delegate.addAll(c);
  this.valueClass = valueClass;
}

相关文章

Collections类方法