Why Zserio templates are not implemented by Java generics? #445
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
-
We have identified the following problems if Zserio templates would be implemented by Java generics:
Primitives types which can be used as template parameters (similarly to C++)
Consider the following easy Zserio template code:
If template parameter is a primitive Zserio type (
uint8
,string
,bool
), there is no way how to deduce corresponded write and read methods from them. For example, primitive typesuint16
andvaruin32
have the same Java mapping toint
type but different coding to the bit stream. Therefore for each possible primitive type, there would have to be a corresponded class wrapper available in the runtime library, e.g. UInt8TemplateParameter, BoolTemplateParameter, etc..Expressions with template parameter
Consider the following Zserio template code:
If there are some expressions with template arguments, Zserio must check the correctness of such expression during each template instantiation. However, Java generic parameters must be an objects with defined interface. There is no way how to define common interface for all possible template parameters which could be used for expressions.
Instantiation of template parameter
There is one specific problem in Java generics. There is no way how to instantiate template parameter. Something like the following command is not possible:
Such instantiation is necessary during reading. This can be solved to pass created empty object in read method or using reflections. But this will complicate things for applications even more.
Beta Was this translation helpful? Give feedback.
All reactions