T
The Abrasive Sponge
So I am creating a method called isStandardProperty and it is returning
true if the Class given is primitive, or a wrapper, or String. Before
I would be able to isAssignableFrom and all is good. In 1.5 API, the
signature it asks for is
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html#isAssignableFrom(java.lang.Class)
public boolean isAssignableFrom(Class<?> cls)
The Class<?> throws me off. I guess this interprets itself as that the
class is representative of some sort of object. In my own words.
Anyways, here is my question, how do I use this method correctly now?
Many of my attempts result in Lint warnings.
/* Attempt 2: Using the .class property
Result : Lint warnings */
private boolean isStandardProperty(Class clazz) {
if (clazz.isPrimitive()) return true;
if (clazz.isAssignableFrom(Byte.class) return true;
if (clazz.isAssignableFrom(Short.class) return true;
if (clazz.isAssignableFrom(Integer.class) return true;
if (clazz.isAssignableFrom(Long.class) return true;
if (clazz.isAssignableFrom(Float.class) return true;
if (clazz.isAssignableFrom(Double.class) return true;
if (clazz.isAssignableFrom(Character.class) return true;
if (clazz.isAssignableFrom(String.class) return true;
return false;
}
/* Attempt 2: Using the types on wrappers
Result : Lint warnings */
private boolean isStandardProperty(Class clazz) {
if (clazz.isPrimitive()) return true;
if (clazz.isAssignableFrom(java.lang.Byte.TYPE)) return true;
if (clazz.isAssignableFrom(java.lang.Short.TYPE)) return true;
if (clazz.isAssignableFrom(java.lang.Integer.TYPE)) return true;
if (clazz.isAssignableFrom(java.lang.Long.TYPE)) return true;
if (clazz.isAssignableFrom(java.lang.Float.TYPE)) return true;
if (clazz.isAssignableFrom(java.lang.Double.TYPE)) return true;
if (clazz.isAssignableFrom(java.lang.Character.TYPE)) return true;
if (clazz.isAssignableFrom(new String().getClass())) return true;
return false;
}
true if the Class given is primitive, or a wrapper, or String. Before
I would be able to isAssignableFrom and all is good. In 1.5 API, the
signature it asks for is
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html#isAssignableFrom(java.lang.Class)
public boolean isAssignableFrom(Class<?> cls)
The Class<?> throws me off. I guess this interprets itself as that the
class is representative of some sort of object. In my own words.
Anyways, here is my question, how do I use this method correctly now?
Many of my attempts result in Lint warnings.
/* Attempt 2: Using the .class property
Result : Lint warnings */
private boolean isStandardProperty(Class clazz) {
if (clazz.isPrimitive()) return true;
if (clazz.isAssignableFrom(Byte.class) return true;
if (clazz.isAssignableFrom(Short.class) return true;
if (clazz.isAssignableFrom(Integer.class) return true;
if (clazz.isAssignableFrom(Long.class) return true;
if (clazz.isAssignableFrom(Float.class) return true;
if (clazz.isAssignableFrom(Double.class) return true;
if (clazz.isAssignableFrom(Character.class) return true;
if (clazz.isAssignableFrom(String.class) return true;
return false;
}
/* Attempt 2: Using the types on wrappers
Result : Lint warnings */
private boolean isStandardProperty(Class clazz) {
if (clazz.isPrimitive()) return true;
if (clazz.isAssignableFrom(java.lang.Byte.TYPE)) return true;
if (clazz.isAssignableFrom(java.lang.Short.TYPE)) return true;
if (clazz.isAssignableFrom(java.lang.Integer.TYPE)) return true;
if (clazz.isAssignableFrom(java.lang.Long.TYPE)) return true;
if (clazz.isAssignableFrom(java.lang.Float.TYPE)) return true;
if (clazz.isAssignableFrom(java.lang.Double.TYPE)) return true;
if (clazz.isAssignableFrom(java.lang.Character.TYPE)) return true;
if (clazz.isAssignableFrom(new String().getClass())) return true;
return false;
}