Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
Description
Currently groovy compiler lets enum constructor invocations from outside the enum class (and its sub-classes) get compiled. Such calls fail at runtime because enum constructors are transformed to add 2 additional parameters in front of the user-provided parameters - 1) identifier, 2) ordinal.
enum Alphabet { A(1), Z(26) private int m_pos; public Alphabet( int pos ) { m_pos = pos; } } /* compiler should reject this invocation as enum constructor are only for internal purposes */ println new Alphabet(2)
In the code above, the call "new Alphabet(2)" fails at runtime because including the 2 internally added parameters, the constructor is <(String,II)V> and not <(I)V>.