• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why is this an error?  RSS feed

 
Guillermo Ishi
Ranch Hand
Posts: 789
C++ Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is this a compile error? On the last line I get "cannot resolve myget". In addition in the declaration it warns "never used"...


 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are trying to call myget on a variable declared as type List.
List does not define a myget method.

If you want to call myget, then your variable type needs to by myarraylist.

 
Guillermo Ishi
Ranch Hand
Posts: 789
C++ Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AHA! Thanks. BTW the reason I'm doing that dumb thing is a complicated h/w algorithm that's one-based and this should (might) make it easier to fathom.
 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are calling the method (here myget) that actually not being defined in the List interface .That is the reason of error .

I am suggesting to read the OPPS concept of java in depth .

Thanks ,
Satya
 
Guillermo Ishi
Ranch Hand
Posts: 789
C++ Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean OOPS? I already knew a base type can't call a subclass method unless the base has a method defined with the same name. Therefore the AHA! when it was pointed out that was the problem.
 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry it should be OOPS (typo ...) , hope understand where is the problem and how to solve this

Satya
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is another interesting error in this line of your code:
Guillermo Ishi wrote:


What you are doing here, is declaring a class myarraylist with a type parameter named String. Note that "String" here is not the name of the class java.lang.String. You just created a type parameter which happens to have the same name as the well-known class String. This is very confusing!

So, don't do this. If you want your class to have a type parameter, don't give it the same name as an existing class. Better use a single, upper-case letter for it (which is the convention that almost everybody uses).

Or, if you did not intend to have a type parameter, then don't add it:

 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!