groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Milles (JIRA)" <>
Subject [jira] [Created] (GROOVY-8703) NamedVariant on constructor
Date Mon, 16 Jul 2018 15:54:00 GMT
Eric Milles created GROOVY-8703:

             Summary: NamedVariant on constructor
                 Key: GROOVY-8703
             Project: Groovy
          Issue Type: Improvement
    Affects Versions: 2.5.1
            Reporter: Eric Milles

Tried this example and got cast exception converting Map to Integer.  Should the print statement
at the end use the generated map constructor as expected?  (Note: I am compiling with indy
variant; tried to use web console to try vanilla MOP...)

import groovy.transform.*
import groovy.transform.options.*

class Color {
  final Integer r, g, b

  @NamedVariant @VisibilityOptions(Visibility.PUBLIC)
  private Color(Integer r, Integer g, Integer b) {
    this.r = r
    this.g = g
    this.b = b

  public static final Color BLACK = new Color(0, 0, 0)

print(new Color(g:12, b:42, r:12)) // gives org.codehaus.groovy.runtime.typehandling.GroovyCastException:
Cannot cast object '{}' with class 'java.util.LinkedHashMap' to class 'java.lang.Integer'

This message was sent by Atlassian JIRA

View raw message