• Post Reply Bookmark Topic Watch Topic
  • New Topic

Strange Syntax  RSS feed

 
Jaime Caetano
Ranch Hand
Posts: 32
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey im going through a school Java Problem, although this is a simple question I can't understand what is this,and it's the first time I see it
theres two paramaters after the interface name, what is this???

I made a class that implements this interface, and its not necessary to put thos paramaters to implement it.
if anyone can help me, I'd really appreciate that;





thanks, Jaime
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those are formal type parameters. I can do no better than to refer you to the appropriate section of the Java Tutorials.
 
Jaime Caetano
Ranch Hand
Posts: 32
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, I checked the oracle tutorial, and now gonna study some videos on youtube ;)
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaime Caetano wrote:
I made a class that implements this interface, and its not necessary to put thos paramaters to implement it.


It's not necessary for backward compatible reasons. And it is not a good idea to mix usage -- either use it or don't, but don't mix it.

Henry
 
Jaime Caetano
Ranch Hand
Posts: 32
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
all right thanks,

I think I got the basic idea, I can pass any kind of object, it will be treated the same way

this fits in as Polymorphism right?

What could be the real uses for generic classes? any real life example you could possible share?

maybe make a generic class with getName() that will work for some section of objects with Stringname?

inlight me brothers

thanks Jaime
 
Arthur Vinicius Rebelo
Ranch Hand
Posts: 30
1
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jaime,

Generics main reason are to enhance compile time type safety.
See:

Another good consequence for using generics is fewer casts:

Now with parameterized type:

Generic also improves the readability of your code. In the example above you could tell from far away that l contains Strings objects without any speculation.

Henry Wong is right, raw types should only be used for backward compatibility with legacy code (code written before generics came to Java).
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arthur Vinicius Rebelo wrote:Generics main reason are to enhance compile time type safety...

Arthur,

Your reply is good, but please DontWriteLongLines, because it makes threads very difficult to read. I've broken yours up this time, but please read the link.

Thanks.

Winston
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaime Caetano wrote:I can pass any kind of object, it will be treated the same way
this fits in as Polymorphism right?

Actually, polymorphism usually means the exact opposite: it means that "it will be treated" according to its actual (runtime) type.

However, generics (at least in Java) is a compile-time tool - ie, it's used to prevent mistakes that can be spotted by the compiler.

What could be the real uses for generic classes? any real life example you could possible share?

Sure: List<E> - in that case 'E' is the type of element that the List holds.

maybe make a generic class with getName() that will work for some section of objects with Stringname?

Possibly, but I really suggest you read the tutorial link that Campbell provided. Generics is simply too big a subject to deal with in a forum like this.

Winston
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaime Caetano wrote: . . . maybe make a generic class with getName() that will work for some section of objects with Stringname? . . . thanks Jaime
Please explain what you mean about generic classes. Didn't the tutorial link explain it all?

And … you're welcome
 
Arthur Vinicius Rebelo
Ranch Hand
Posts: 30
1
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Winston Gutkowski ;)
 
Jaime Caetano
Ranch Hand
Posts: 32
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did not read the entire tutorial, I solved my school problem half way,
apparently they just wanted to introduce the idea.

I was just trying to get some more info out of you people, I'm now going deeper with
the interfaces,

most likely i'll be doing another post

thank you all, I really appreciate your attention

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