Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

When are two classes the same? If the name is equal and if the class loader is equal. This means you can have multiple versions of the same class if you load the class through different class loaders. Of course this versions don't really have to be the same. This also means if you have code like

Code Block
borderStylesolid
titleDuplicateClass.groovy
borderStylesolid
Class cls = foo.class
assert cls.name==Foo.class.name
assert cls==Foo.class

may fail because cls is not Foo. This also means calling a method like

Code Block
borderStylesolid
titleDuplicateClass.groovy
borderStylesolid
def f(Foo f){
  println "f(Foo) called"
}

def f(Object o){
  println "f(Object) called"
}

...

If you assign a value to a typed variable in Groovy, then this assignment will include an implicit cast. A Declaration counts as assignment in that sense as well.

Code Block
borderStylesolid
titleAssignment.groovy
borderStylesolid
String x = 8

is in fact

Code Block
borderStylesolid
titleAssignmentExpanded.groovy
borderStylesolid
String x = (String) 8

Note: there is nothing to be done but boxing, if the cast is to Object, since everything in Groovy is an Object. The cast is realized in Groovy by writing ScriptByteCodeAdapter.castToType(8, String.class), which in turn will call DefaultTypeTransformation.castToType(Object, Class).

...