NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Private member variables and generics - Netbeans doesn't like it?

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
jcc153



Joined: 27 Sep 2008
Posts: 4

PostPosted: Wed Jan 27, 2010 6:14 pm    Post subject: Private member variables and generics - Netbeans doesn't like it? Reply with quote

The code below compiles and runs perfectly, but Netbeans complains about line 10 saying 'enginePower has private access in Car'. NetBeans is correct, but by my understanding this shouldn't be a problem?

Apologies for the contrived example!


Code:
public class Car<C extends Car> {

  private int enginePower;

  public Car(int enginePower) {
    this.enginePower = enginePower;
  }

  public boolean isCarBigger(C otherCar) {
    return otherCar.enginePower > enginePower;
  }


  public static void main(String[] args) {
    Car car1 = new SmallCar();
    Car car2 = new BigCar();

    if (car1.isCarBigger(car2)) {
      System.out.println("Car 2 is bigger than car 1");
    } else {
      System.out.println("Car 2 is smaller than car 1");
    }
  }
}

class SmallCar extends Car {
  public SmallCar() {
    super(5);
  }
}

class BigCar extends Car {
  public BigCar() {
    super(20);
  }
}



I'm running NetBeans v6.7.1 on Ubuntu with Java 1.6.0_16.

Cheers
--J
Back to top
Thomas Wolf
Posted via mailing list.





PostPosted: Wed Jan 27, 2010 6:45 pm    Post subject: Private member variables and generics - Netbeans doesn't like it? Reply with quote

Maybe I'm missing something obvious, but why do you have to use generics at all in this example? If you got rid of the "<C extends Car>" and changed isCarBigger(C otherCar) to isCarBigger(Car otherCar), do you still get the complaint from Netbeans?

tom

On 01/27/2010 01:14 PM, jcc153 wrote:
Quote:
Quote:
The code below compiles and runs perfectly, but Netbeans complains about line 10 saying 'enginePower has private access in Car'. NetBeans is correct, but by my understanding this shouldn't be a problem?

Apologies for the contrived example!



Code:
public class Car<C extends Car> {

private int enginePower;

public Car(int enginePower) {
this.enginePower = enginePower;
}

public boolean isCarBigger(C otherCar) {
return otherCar.enginePower > enginePower;
}


public static void main(String[] args) {
Car car1 = new SmallCar();
Car car2 = new BigCar();

if (car1.isCarBigger(car2)) {
System.out.println("Car 2 is bigger than car 1");
} else {
System.out.println("Car 2 is smaller than car 1");
}
}
}

class SmallCar extends Car {
public SmallCar() {
super(5);
}
}

class BigCar extends Car {
public BigCar() {
super(20);
}
}




I'm running NetBeans v6.7.1 on Ubuntu with Java 1.6.0_16.

Cheers
--J




IMPORTANT: The contents of this email and any attachments are confidential. They are intended for the named recipient(s) only.
If you have received this email in error, please notify the system manager or the sender immediately and do not disclose the contents to anyone or make copies thereof.
*** eSafe scanned this email for viruses, vandals, and malicious content. ***
Back to top
jcc153



Joined: 27 Sep 2008
Posts: 4

PostPosted: Wed Jan 27, 2010 7:15 pm    Post subject: Re: Private member variables and generics - Netbeans doesn't like it? Reply with quote

Hi Tom

No you're not missing anything! That contrived code snippet is just to reproduce the behaviour we're seeing with a much bigger project, based on the Assembly Line pattern and which uses generics to great effect. I appreciate the example code is a bit silly!

Ignoring the specifics of the code design for a moment, I think my question is more about whether NetBeans should be complaining at all when, by my understanding, it is valid Java code which compiles and runs correctly?


Thomas Wolf wrote:
Maybe I'm missing something obvious, but why do you have to use generics at all in this example? If you got rid of the "<C extends Car>" and changed isCarBigger(C otherCar) to isCarBigger(Car otherCar), do you still get the complaint from Netbeans?

tom
Back to top
Franz
Posted via mailing list.





PostPosted: Thu Jan 28, 2010 8:13 am    Post subject: Private member variables and generics - Netbeans doesn't like it? Reply with quote

Hello,

Am 27.01.2010 19:14, schrieb jcc153:
Quote:
The code below compiles and runs perfectly, but Netbeans complains about line 10 saying 'enginePower has private access in Car'. NetBeans is correct, but by my understanding this shouldn't be a problem?

I came across this some time ago as well (and it seems I wasn't the
first one). The answer you're looking for is here:
https://netbeans.org/bugzilla/show_bug.cgi?id=169907
https://netbeans.org/bugzilla/show_bug.cgi?id=163763

Regards
franz
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo