• 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

Understanding Interfaces

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Bartender
Posts: 689
17
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 115
11
IntelliJ IDE Clojure Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Marshal
Posts: 76462
366
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 76462
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 76462
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Auto-correction strikes again!
 
Campbell Ritchie
Marshal
Posts: 76462
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or is it predictive clairvoyant text?
 
Catch Ernie! Catch the egg! And catch this tiny ad too:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic