-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keep reference to type of SimpleNode value #9
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that class of object need to store . I'm not thrilled to have to figure out the type of list item by specific objects, there may still be another way. Could you investigate this?
} | ||
|
||
@Override | ||
public Object getValue() { return value; } | ||
|
||
public Class<?> getClassOfValue() { return classOfValue; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public Class<?> getClassOfValue() { return classOfValue; } | |
public Class<?> getValueClass() { return valueClass; } |
I bet, that this name is better.
/** Replace value.getClass() when value==null. */ | ||
private final Class<?> classOfValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** Replace value.getClass() when value==null. */ | |
private final Class<?> classOfValue; | |
/** Class of property, represented by the getter return value. */ | |
private final Class<?> valueClass; |
value.getClass()
is slightly incorrect, because it is dynamic type, but in fact the static type is stored here. For example ArrayList
vs List
if (nonNullElement.isPresent()) { | ||
valueClass = nonNullElement.get().getClass(); | ||
} else { | ||
valueClass = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to avoid null
in that field:
valueClass = null; | |
valueClass = Object.class; |
final Optional<?> nonNullElement = value.stream().filter(Objects::nonNull).findAny(); | ||
if (nonNullElement.isPresent()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like the idea of looking at the content, because the type will depend on the specific object. Probably it is possible to extract some type from generic boundaries? I remember, that this should be possible.
Regarding ListNode.java, I agree, the way I did it is dissatisfying. I read some StackOverflow. Type erasure does apply here, if you do: new ArrayList<Integer>().getClass().getTypeParameters()[0].getBounds() it just returns:
But we can do what we want using the
Via https://stackoverflow.com/a/1942680/7376577 I will push some more changes to this branch |
Thanks! |
This is for my idea to add different colored icons for different data types, mentioned in issue #8.
The
value
field in SimpleNode.java is anObject
, so when it isnull
we cannot tell what type it is. This PR adds fieldClass classOfValue
.KSY to easily get a null value:
Screenshot:
The code in ListNode.java is kind of gross. We can't check the generic type of an ArrayList at runtime because of type erasure. So, I look for a non-null element in the List and check its type.