Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

K&B SCJP5 pg 574 - Generics

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm refering to the codes found in K&B SCJP5's book at page 574.

Here it goes...
Then you have a line of code calling the getDogList() method as follows:

I'm just wondering how it is possible to call getDogList() method though it is not a static method.

Thanks

_Charles
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post the context from which this method is called. Give us some more lines of code including the method signature itself. Perhaps it is a valid errata
 
Charles Chikito
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bala,

The discussion was focused on generic collection. This example doesn't have any complete program except the Dog class.

The point that is being stressed here is that the method won't need a cast to take Dogs from the List.

So, the line
Dog d = getDogList().get(0); // We know it will return a Dog

I do understand this point but unable to understand

how it is possible to call getDogList() method though it is not a static method



Let me know if you need more information...

Thanks

_Charles
 
Ranch Hand
Posts: 537
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simple its not within a static context. Its most probably a has-a instance variable or in a instance method. The important thing here is you can get a list<dog>.get(0) means a dog object at index 0 from the list and then assign it to dog d.
 
Charles Chikito
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bangera,

Probably you are right...

most probably a has-a instance variable or in a instance method



Thanks

_Charles
 
Who knew that furniture could be so violent? Put this tiny ad out there to see what happens:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic