本文介绍了原始(wrapper)实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
/> Google Guava 项目提供了,可用作:

  Primitives.isWrapperType(e.value()。getClass ))


This may sound moronic, but please forgive me, I'm working with moronic code. What is the best way, given a collection of objects, to identify which are primitives, or more accurately, wrappers around primitives.

Suppose I want to print all primitives:

HashMap<String,Object> context = GlobalStore.getContext(); // Some bizarre, strangely populated context
for(Entry<String,Object> e : context.entrySet()){
   if(e.value() instanceof PRIMITIVE){ // What goes here?
        System.out.println(e);
   }
}

Is this possible, other than by enumerating all primitives one by one?

解决方案

The excellent Google Guava project provides a Primitives.isWrapperType(Class) which could be used as:

Primitives.isWrapperType(e.value().getClass())

这篇关于原始(wrapper)实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 15:31