groovy

Late and superfluous setting of default values on primitives in subclasses

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0, 1.1-beta-3, 1.1-rc-1, 1.1-rc-2, 1.1-rc-3
  • Fix Version/s: 1.6-rc-1, 1.5.8, 1.7-beta-1
  • Component/s: class generator
  • Labels:
    None
  • Environment:
    Tested Linux jdk1.5.0_13, 1.6.0_03, 1.6.0_10
  • Number of attachments :
    0

Description

b=new B(42)
   println "finally, intA=$b.intA, strA=$b.strA"
   println "         intB=$b.intB, strB=$b.strB"

   class A {
      int intA
      String strA

      A(int a) {
         intA=a
         strA=intA as String
         println "in A.<init> intA=$intA strA=$strA"
         config()
      }

      void config() {
         println "in A.config intA=$intA strA=$strA"
      }
   }

   class B extends A{
      int intB
      String strB

      B(int a) {
         super(a)
         println "in B.<init> intB=$intB strB=$strB"
      }

      void config() {
         super.config()
         intB=intA-1
         strB=intB as String
         println "in B.config intB=$intB strB=$strB"
      }

   }

The output is as follows:

in A.<init> intA=42 strA=42
in A.config intA=42 strA=42
in B.config intB=41 strB=41
in B.<init> intB=0 strB=41
finally, intA=42, strA=42
intB=0, strB=41

As rtayek@ca.rr.com pointed out already:

> calling a virtual config from a ctor seems a bit strange, but it seems to work in java. it may be a boxing issue. decompiling B.class, the ctor has:
>
> Integer integer = new Integer(0);
> integer;
> intB = DefaultTypeTransformation.intUnbox(integer);
>
> in it after the call to super.

So I would state this as a bug. Rather major in my opinion, either.

Activity

Hide
blackdrag blackdrag added a comment -

fixed

Show
blackdrag blackdrag added a comment - fixed

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: