Java Generics in Java Generics in Java Generics Quiz

bot .net
bot .net
10,260 Points

Why the answer is all of those?

Hi, i dont understand why the answer is all of theseto the question: Which of these objects can we pass in to the logPresentr method?

Is it because <P> extends Object?, like <T>? Tonnie Fanadez

2 Answers

Tonnie Fanadez
Tonnie Fanadez
UX Design Techdegree Student 13,604 Points

Hi noob developer

It should be all of them.

Just remember in Java we can define our own classes type and give them whatever name we can think of. Sock is-a(n) Object because it extends/inherits from Object Class. Chocolate Class is-a Object. A collection of Amazon Gift Cards is also an Object since a Gift Card Type is-a child of the Object Super-class.

In short *All Java Class Types * inherit their properties from the Object Class.

In return Objects of the same type can be grouped together using Collections (*Lists, Sets, Maps or Queues *).

In Collection<T> T is just a placeholder and any child of Object Class can be inserted in between the diamond brackets.

bot .net
bot .net
10,260 Points

Hi Tonnie Fanadez how are u? So am i right with my question or no?, <P> is like <T>, <P> its a placeholder and any child of Object?

btw How's the techdegree, what u learn there?

Tonnie Fanadez
Tonnie Fanadez
UX Design Techdegree Student 13,604 Points

Hi noob developer

You're correct both <P> and <T> are the same, they are placeholders.

UX design is fantastic and it teaches how to be creative and lot of exposure across IT fields. I am liking it and will keep you posted.