Trouble with generics - using a class method within a generic function

Stuart Rogers

Ranch Hand

Posts: 141

posted 7 years ago

Greetings all,

I've several classes, each consisting of an assortment of Strings and each containing a function getAsArray which returns the contents of the object as a String array.
Here an example from one specific class named Asset_HP :

In the program I populate several LinkedLists , one for each class.

I'd like to craft one generic function to write out a LinkedList like so:

instead of hardcoding a Write function for each LinkedList like this specific example for one list and one class:

what do I need to make this work? Or should I be using some other approach?

Something other than Java, due to this line:As Gregg says, you'll need to work around the fact that Java's generics are available at compile-time only.

The variable names "lisst" and "roww" confuse me; do the extra letters have some internal significance?

Stuart Rogers

Ranch Hand

Posts: 141

posted 7 years ago

I deliberatley misspell my variable names so they can never be confused with typenames or anything that could be construed as part of the language itself. How many times have you seen this in a textbook?

List list = new List();

or this from C++ :

typedef int LENGTH;
LENGTH length;

in Java lots of objects inherit a .length() method.

Back to the question at hand, perhaps I should suppress warnings in my IDE for that particular function and try it "as-is".