Hi Marco, thanks for the reply.
I was also thinking, that throwing an error could be the default, but it depends on the use case.
For the default exception, the UnsupportedOperationException is a reasonable choice in my opinion. It's easy to understand even without an error message. But both would be customizable with the annotation attributes.
For the other option, when the generated methods won't throw an error, but silently doing nothing, then the default return values should be as simple as possible.
In my opinion, the "zero, null and empty" are good options. My reasoning is that these auto-generated methods should avoid additional complexity and ambiguity. The following mapping could be sufficient:
* primitive types: default primitive value
e.g. 0 for an int, 0L for a long, '0' for a char, false for a boolean, and so on
* String: null
could be an empty string, but that's not the default in Java
* collections: empty collection
list, set, map, and so on, including the sorted versions
the only question is the mutability, i.e. should it be "return new ArrayList<>()" or "return Collections.emptyList()" instead?
I think, the immutable collections are a better option, for the auto-generated methods. If anything else is needed, then those methods should be manually implemented.
* Optional: Optional.empty()
* arrays: empty array
* any other object type: null
that seems to be the easiest and safest option for the code generator
Let's say that there is a "silent" attribute of the @Attribute annotation. It's default value is 'false', meaning that the generated methods are throwing an exception. The silent=true means that the generated methods are returning default values as described above and the void methods are silently not doing anything at all.
The original intention with the @Adapter annotation is to eliminate the boilerplate code from the source files. So, it should work like the IDE when you create a new class and instruct the IDE to generate methods for any implemented interface methods. The only difference, that in this case those methods won't clutter the code base.