本文整理匯總了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));
}
}