Replies: 6 comments 7 replies
-
Java language does not support some alternative to C++ typedef. Therefore subtypes in Java is resolved during API generation (resolved means that generated Java API uses always original type directly). We might consider to use duplication or inheritance in the previous example but we will still have a problem for native types:
Besides of that,
So, because Zserio language uses alias, we must find out the real alternative in Java to be able to generate working code. |
Beta Was this translation helpful? Give feedback.
-
Regarding problem with native/primitive types, we might think to use objects instead of them. In this case, we will be hit by significant memory and performance penalty. The fresh comparison of memory and performance between primitives and objects is available at https://www.baeldung.com/java-primitives-vs-objects. |
Beta Was this translation helpful? Give feedback.
-
The solution for classes (not for native/primitive types) could be if subtypes will be modeled by inheritance of original types and original types will be used everywhere instead of subtypes. Or maybe even better original types will define interface which will be implemented by all subtypes. |
Beta Was this translation helpful? Give feedback.
-
Note that even with interfaces the getters will still return only the interface, so that the following Java code will not compile: someZserioObject.setMyField(new MySubtype(10)); // here it works since MySubtype will down-cast to MyBaseType
final MySubtype field = someZserioObject.getMyField(); // myField member will always be of type MyBaseType and thus the up-cast will not work automatically The member cannot by of type |
Beta Was this translation helpful? Give feedback.
-
We have created a corresponded design note to put together what we have learned in this issue. |
Beta Was this translation helpful? Give feedback.
-
Please see issue #578 as well. |
Beta Was this translation helpful? Give feedback.
-
Consider the following schema:
When generating the API for Java, there is no class/type-identifier
MyType
available, for Python and C++ there is.I expected that
subtype
defines something that has to be provided by the API regardless of the target language.Beta Was this translation helpful? Give feedback.
All reactions