PropertyDefinition.getType() silently converts primitive class to its boxed counterpart
See original GitHub issueDescription
I’d expect PropertyDefinition.getType() to return the actual type of the field (e.g. int.class
) and not the boxed counterpart (Integer.class
). Please either make getType() return the actual type, or document that it will return the class of the boxed counterpart (+provide a function named getActualType() that returns the original type, e.g. primitive int.class).
Expected outcome
Minimal reproducible example
Steps to reproduce
Environment
Vaadin version(s): 14.8.11 OS: Windows
Browsers
No response
Issue Analytics
- State:
- Created a year ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Autoboxing and Unboxing
Autoboxing is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes.
Read more >Groovy Language Documentation
Automatic boxing and unboxing occur when, for instance, calling a method requiring the wrapper class and passing it a primitive variable as the...
Read more >How To Test if Type is Primitive - Stack Overflow
This was the result of my query: Type contextType = context.GetType(); var props = (from property in contextType.GetProperties() let name ...
Read more >Index (XStream Core 1.4.11.1 API) - Javadoc.io
Converts a byte primitive or java.lang.Byte wrapper to a String. ByteConverter() - Constructor for class com.thoughtworks.xstream.converters.basic.
Read more >Index (Guava: Google Core Libraries for Java 23.3-android API)
This class provides a skeletal implementation of the Cache interface to minimize ... Returns a Converter that converts values using bimap.get() , and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you Leif. My use-case: calculating default values. The default value of
int.class
is 0 while ofInteger.class
is null. I was building a FilterBar showing closable filter “pills” for filter fields with different than the default value.In this example, the “Active Only” filter bean is primitive
boolean
with the default value of false; the FilterBar only displays the “Active Only” “pill” when it’s different from the default value, which in this case is false. For booleans it probably doesn’t make much sense (3-state vs 2-state boolean logic is not a sound example 😄 ) but it makes much more sense for, say,int.class
.Note the red cross button which resets the filter to the default value, which is
null
for Objects but a non-null value for primitives. I was using the PropertyDefinition API to figure out the default value and setting nulls via reflection, which gave me exceptions… hence the issue.Done.