Why subtype is not used in generated Java code? #447
Locked
mikir
announced in
Design Notes
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Java language does support any 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 inheritance for objects and to model subtypes by inheritance of original types and to use original types everywhere instead of subtypes. Or maybe even better original types will define interface which will be implemented by all subtypes. Then, we will be hit by the following problems:
The inheritance will not work for primitive types. Example::
We might think to use objects instead of them. Besides of the clumsy interface (because operators are not possible to overload, we would need something like
setValue()
orgetValue()
), we will be hit by significant memory and performance penalty.The getters will still return only the original type or the interface, so that the following Java code will not compile. Example:
The member cannot by of type MySubtype since it then wouldn't be possible to call setter with MyBaseType.
Because of previous problems, Java extension just generates subtypes for compound types using inheritance of base types but such generated classes are not used anywhere. They are just meant to be used by application for deserialization.
See Also:
Beta Was this translation helpful? Give feedback.
All reactions