You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(on jdk7 u45, using maven/javac)
Could we somehow get rid of additional class ImmutableMy$1.class being compiled? Is this somehow related to inner class private access bridge?
The text was updated successfully, but these errors were encountered:
Having investigated that I've found that this class is a synthetic access-bridge class. Private fields of builder object accessed in immutable class constructor, this somehow require this unwanted class to be generated
Curiously, but Eclipse compiler do not require such class, probably static accessor methods are enough for ECJ.
My current idea is to leave this as is for a while, but we could revise how code is generated in that place.
Long ago there we no builder object passing to immutable class constructor, constructors with high count of parameters was used where all attributes was passed separately, so builder just need to access private constructor of enclosing class (via simple synthetic static method) -- this will probably wont require additional class by Javac
JFYI at that time we fought checkstyle rules where high arity method and constructors were not allowed, don't know
if it is important now since we moved to annotation processing, so generated-sources could be made skipped if check-style is used.
Immutable constructor accesses private fields of Builder
Builder access private constructor of Immutable
ECJ creates package-private static synthetic methods to compile this
Javac might generate whole synthetic class to bridge this
Either we relax access restriction and expose package-private methods/constructor in generated code.
Or we will live with whatever compiler generates in hope that runtime inlines everything it can.
Currently I do not want to expose package-private methods. Closing as won't fix, but we could return to this later.
Hi, I've made simplest possible immutable class with builder and got following classes in jar
My.class
ImmutableMy.class
ImmutableMy$Builder.class
ImmutableMy$1.class
(on jdk7 u45, using maven/javac)
Could we somehow get rid of additional class
ImmutableMy$1.class
being compiled? Is this somehow related to inner class private access bridge?The text was updated successfully, but these errors were encountered: