Details
-
Type:
Sub-task
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.5.6
-
Fix Version/s: None
-
Component/s: groovy-jdk
-
Labels:None
-
Number of attachments :
Description
Disable overriding via MOP for the following interfaces, classes and methods
java.lang.CharSequence charAt(int) length() subSequence(int, int) java.lang.Comparable compareTo(T) java.lang.Number byteValue() doubleValue() floatValue() intValue() longValue() shortValue() java.lang.Object equals(Object) getClass() hashCode() toString() java.lang.Boolean <all methods> java.lang.Byte <all methods> java.lang.Short <all methods> java.lang.Integer <all methods> java.lang.Long <all methods> java.lang.Double <all methods> java.lang.Float <all methods> java.lang.Enum getDeclaringClass() name() ordinal() java.lang.String <all methods> java.lang.StringBuffer <all methods> java.lang.StringBuilder <all methods>
Overriding these methods
- does not make sense,
- adds significant runtime overhead to GDK methods,
- is not thoroughly respected by runtime libraries, epecially the JRE, and
- would require to change class file generation (e.g. for concatenated literals).
This issue is related to http://jira.codehaus.org/browse/GROOVY-2599.
Activity
blackdrag blackdrag
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Parent | GROOVY-2503 [ 61571 ] | |
| Issue Type | Improvement [ 4 ] | Sub-task [ 7 ] |
let us discuss this a bit please... First... there is always a static and dynamic aspect of a class. We can change the dynamic, but not the static aspect. Javacode will normally only act on the static aspects. This is true especially for classes from java.lang, but is a general "problem". For example if you create a class in Groovy or Java and then call a method that exists in the static aspect from Java, then the method in the static aspect will be called, totally ignoring the MetaClass and with it any dynamic aspect. The only way to change that right now would be by changing the bytecode itself, which is possible sometimes, but is not a way we want to go. Your last point is invalid, because the current way is aöready a way that respects dynamic methods. For example for "a"+"b" we could have theoretically an alternative plus implementation, which may lead to a different result than "ab".
When you say "don't overwrite" I guess you actually mean the GDK methods too. But why are interfaces in the list? Any method bound to that interface would normally be overwritten by the actual implementation of the interface anyway.
As for your point "performance"... it is kind of funny, because we already decided to go away from the pure the static way in GDK methods we try to follow most of the time. For example equals... even if equals(Object) is locked for changes, you can still overload the method by using a more specific parameter type, thus requiring dynamic dispatch because of multi methods. It was a requirement to enable overloaded equals methods in GDK methods. But if we go with equals, then why not with the others too? You see we are trying to improve Groovy's performance big times, but the ultimate goal is still to have most of Groovy written in Groovy itself, especially the GDK methods. We don't fear the performance, because as with 1.6 we have ways to improve and we continue working on that part.
So if your only reason for "doesn't make sense" is performance then the argument doesn't make sense to me. Your point 3 is a general mismatch between Java and Groovy and is owed to the fact that we cannot change methods as we like for Java. Which is more or less your point 4.
So I guess you need to explain "doesn't make sense" a bit more.