Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Understanding Interfaces  RSS feed

 
courtney young
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code isn't actually asking me to do anything. I'm just trying to study it to figure out what my professor is doing in his code.
(He built a list interface that resembles the one the Java API uses.)

My questions are:

I'm finding it hard to understand the use of interfaces and his <AnyType> in the interface heading.
What does it mean? And what does it mean when he uses this: Node<AnyType extends Comparable<? super AnyType > in his class for node?
If anyone could help me to understand these two files, I would be so grateful!



He also created a Node class that uses this interface:
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
courtney young wrote:I'm finding it hard to understand ... his <AnyType> in the interface heading.
What does it mean? And what does it mean when he uses this: Node<AnyType extends Comparable<? super AnyType > in his class for node?


Pawl already answered that in your previous thread.
Paweł Baczyński wrote:It is a name of a generic parameter of OP's ArrayList class.
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at the Oracle Tutorial on generics. It will explain it better than we can.

http://docs.oracle.com/javase/tutorial/extra/generics/index.html
 
Jason Bullers
Ranch Hand
Posts: 115
11
Clojure IntelliJ IDE Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also see http://docs.oracle.com/javase/tutorial/java/generics/types.html

A bit of an aside since it seems that the question was already answered. One thing that stood out to me in that code was the type parameter being called AnyType. I'm going to assume your instructor did that for illustrative purposes, but I want to point out that the established convention in Java is to go with single letter names such as T (for type), etc. I personally find code that doesn't follow that convention confusing. E getElement() is obviously returning a parameterized type (because it follows the single letter convention). It isn't so obvious that AnyType getElement() is returning a parameterized type and not an object of type AnyType.
 
courtney young
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I looked at the tut on generics and I am starting to understand what he was doing in his code. Thanks for the help all!
 
Campbell Ritchie
Marshal
Posts: 55691
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have another look at the tutorial. Leave it for a week and have another look at the tutorial. Java® generics is by no means easy to understand. I suspect it would have been a lot easier to understand had it been implemented in Java1.0, but it wasn't. It was implemented in Java5 and the fiddles they did to maintain backwards compatibility may have made it harder to understand.
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well in a few releases we'll have generic primitives Campbell, so be prepared for added complexity.
 
Campbell Ritchie
Marshal
Posts: 55691
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that a promise or a threat?

I remember how long they have been threatening to ban raw types in new code and I haven't seen that implemented yet.
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never considered threatening someone with complicated genetics before, interesting idea!

Look up Project Valhalla for more info. Looks like it will be interesting and probably some good performance gains, but more hoops to jump through to maintain compatibility.
 
Campbell Ritchie
Marshal
Posts: 55691
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Complicated genetics?


Yes, I suppose that is correct. I must be somebody with complicated genetics. There can be no other explanation for me
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Auto-correction strikes again!
 
Campbell Ritchie
Marshal
Posts: 55691
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or is it predictive clairvoyant text?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!