Issue Details (XML | Word | Printable)

Key: GROOVY-1314
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Jochen Theodorou
Reporter: Alex Lam S.L.
Votes: 1
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
groovy

support covariant return types (& generics)

Created: 04/May/06 06:53 PM   Updated: 11/Oct/07 06:11 PM   Resolved: 11/Oct/07 06:11 PM
Return to search
Component/s: None
Affects Version/s: 1.0-JSR-5
Fix Version/s: 1.1-rc-1

Time Tracking:
Not Specified

File Attachments: 1. Zip Archive generics.zip (2 kB)

Issue Links:
Duplicate
 
dependent
 


 Description  « Hide

CRT is really useful, even if Generics is not fully supported / implemented



Jochen Theodorou added a comment - 05/May/06 11:05 AM

covariant return types means usually to have two method withe the same name and the same parameter types, but diefferent return types. Groovy does support this already:

class A{
void foo(){}
Object foo(){}

}

A.class.declaredMethods.each{println it}

and you get:
public void A.setProperty(java.lang.String,java.lang.Object)
public java.lang.Object A.getProperty(java.lang.String)
public java.lang.Object A.invokeMethod(java.lang.String,java.lang.Object)
public groovy.lang.MetaClass A.getMetaClass()
public void A.setMetaClass(groovy.lang.MetaClass)
static java.lang.Class A.class$(java.lang.String)
public void A.foo()
public java.lang.Object A.foo()

there are 2 foo methods, so the methods are there. To do it like java means to let one of it redirect to the other automatically. This part is missing, yes.

btw, you can only call only one of these methods!


Alex Lam S.L. added a comment - 05/May/06 11:45 AM

ah - there's a problem though:

abstract class Numeric {
abstract Numeric eval();
}

class Rational extends Numeric {
Rational eval() {
this
}
}

this would have Groovy complaining that eval() in Numeric is not implemented


Jochen Theodorou added a comment - 10/May/06 09:20 AM

I think, to fully support this we have to generate 1.5 bytecode. We decided not to do this before 1.0, so this does have to wait. After 1.0 we will have to discuss how we support generics.


Guillaume Laforge made changes - 20/Jan/07 03:27 PM
Field Original Value New Value
Assignee Guillaume Laforge [ guillaume ]
Kennard Consulting added a comment - 02/Apr/07 11:51 PM

Please note that even if Groovy decides to ignore generics because it is already a dynamically typed language, it is still important that it generate the correct 1.5 generics bytecode, including all the generics metadata.

Even after erasure, there is still a good deal of generics metadata present in the bytecode of Classes, Methods and Fields, and many significant frameworks (JPA, Spring) depend on this.

A prominent use case would be trying to define an EJB3 entity bean using GroovyBeans...

@Entity
class Foo
{
@OneToMany
Set<Bar> bars;
}

...it is important that groovyc maintain the generics information when it compiles the class.


Emmanuel added a comment - 17/Apr/07 07:13 PM

Here is an example of useful inheritance of Generics, including test case. drop it in src/test/groovy/tiger
As Kennard pointed out, it's something important to achieve a friendly integration with JavaEE and their frameworks, esp JPA


Emmanuel made changes - 17/Apr/07 07:13 PM
Attachment generics.zip [ 26854 ]
Guillaume Laforge made changes - 18/Apr/07 02:43 AM
Fix Version/s 1.1-beta-1 [ 13164 ]
Jochen Theodorou made changes - 27/Apr/07 02:12 PM
Fix Version/s 1.1-beta-1 [ 13164 ]
Fix Version/s 1.1-beta-2 [ 10436 ]
Assignee Jochen Theodorou [ blackdrag ]
Jochen Theodorou made changes - 17/May/07 08:16 AM
Link This issue is duplicated by GROOVY-1860 [ GROOVY-1860 ]
Jochen Theodorou added a comment - 01/Jul/07 10:38 AM

as commented in GROOVY-1860 a bigger refactoring is needed here, so I will have it postponed to beta-3


Jochen Theodorou made changes - 01/Jul/07 10:38 AM
Fix Version/s 1.1-beta-3 [ 13590 ]
Fix Version/s 1.1-beta-2 [ 10436 ]
Jochen Theodorou made changes - 01/Jul/07 01:29 PM
Link This issue is depended upon by GROOVY-1962 [ GROOVY-1962 ]
Jochen Theodorou made changes - 01/Jul/07 01:30 PM
Link This issue is depended upon by GROOVY-1962 [ GROOVY-1962 ]
Jochen Theodorou made changes - 01/Jul/07 01:30 PM
Link This issue depends upon GROOVY-1962 [ GROOVY-1962 ]
Guillaume Laforge made changes - 20/Sep/07 03:11 PM
Fix Version/s 1.1-beta-3 [ 13590 ]
Fix Version/s 1.1-rc-1 [ 13165 ]
Jochen Theodorou added a comment - 11/Oct/07 06:11 PM

fixed


Jochen Theodorou made changes - 11/Oct/07 06:11 PM
Status Open [ 1 ] Closed [ 6 ]
Resolution Fixed [ 1 ]