本文整理汇总了Java中java.util.Set.getClass方法的典型用法代码示例。如果您正苦于以下问题:Java Set.getClass方法的具体用法?Java Set.getClass怎么用?Java Set.getClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Set
的用法示例。
在下文中一共展示了Set.getClass方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import java.util.Set; //导入方法依赖的package包/类
public void write(Packer pk, Set<E> target, boolean required)
throws IOException {
if (!(target instanceof Set)) {
if (target == null) {
if (required) {
throw new MessageTypeException("Attempted to write null");
}
pk.writeNil();
return;
}
throw new MessageTypeException("Target is not a List but "
+ target.getClass());
}
pk.writeArrayBegin(target.size());
for (E e : target) {
elementTemplate.write(pk, e);
}
pk.writeArrayEnd();
}
示例2: unmodifiableCopyOfEnumSet
import java.util.Set; //导入方法依赖的package包/类
/**
* Returns an unmodifiable versions of the Set of Enums. If the contents of the set are known
* to be unmodifiable by the caller in any way, the set itself will be retured, otherwise an
* unmodifiable copy of the Set will be returned.
* @param s Set to get the tamper-proof version of
* @return An unmodifiable tamper-proof version of the set
*/
public static <E extends Enum<E>> Set<E> unmodifiableCopyOfEnumSet(Set<E> s)
{
Class<? extends Set> copyClass = s.getClass();
if ((_EMPTY_SET == copyClass) || (_SINGLETON_SET == copyClass))
{
// these classes are already unmodifiable, so just return
return s;
}
else
{
return Collections.unmodifiableSet(EnumSet.copyOf(s));
}
}