Topic: Any programmers on deck?

Posted under Off Topic

Hey, got a Java assignment due in for my uni in a few hours, and I still have no godly idea what I'm doing with generics. See I have:

public E next()
{
E value;
if(hasNext())
{
value=iterNext.getValue();
iterNext=iterNext.getNext();
}
else
{
value=null;
}

return value;
}

As part of a tailored linked list, and now we have to make it generic (was handling Object class objects before, and I understand WHY WE SWITCHED, I just don't really get HOW TO WORK WITH IT)

.getValue() is simply:

public E getValue()
{
return value;
}

Where value has been declared as E

However, based on the compiler output, it looks like getValue() is still trying to hand back an Object, but I don't get why... any help forthcoming?

...Where's my stupid?

Updated by AmericanExistence

I'm somewhat certain you would be better off asking this on a java forum.

Ooor searching the web for help on the subject.

Java is a fairly widespread language, I'm certain you could dig up help easily.

Updated by anonymous

I suppose you have correctly declared it like:

public class WhateverList<E> implements List {
...

Updated by anonymous

I'd ask /r/learnprogramming or just /r/programming they are often pretty good at solving issues.
Also you have to percolate the java before you get anything worth drinking.

Updated by anonymous

Generics in Java are implemented via type erasure, meaning the compiler statically (at compile time) ensures type safety, but afterwards the type parameter is lost. The produced code only handles the most generic type. When there is no bound this type is Object.

This is in contrast to C++ where specialized code is generated for each set of parameters for a template.

Updated by anonymous

I've literally just started an intensive programming course, sadly it's all Ruby and web design. No java love!

Updated by anonymous

Shit. I haven't coded in Java in forever.

Come to think of it, I haven't coded anything for a while.

Time to get back on that...
Brb gotta go hack some sites

Just kidding!

.
.
.
OR AM I?!?!?

Updated by anonymous

  • 1