public GenericNode( E val )
is correct. Inserting <E> after GenericNode would be incorrect syntax.
Here is a program that tests GenericNode.
public class GenericNodeTester
{
public static void main (String args[])
{
GenericNode<Float> nodeA = new GenericNode<Float>( 5.5f );
System.out.println("nodeA: " + nodeA );
nodeA.setValue( 5.0f );
System.out.println("nodeA: " + nodeA );
GenericNode<String> nodeB = new GenericNode<String>( "Good Dog Carl" );
System.out.println("nodeB: " + nodeB );
nodeB.setValue( "The Cat in the Hat" );
System.out.println("nodeB: " + nodeB );
GenericNode<Integer> nodeC = new GenericNode<Integer>( 45);
System.out.println("nodeC: " + nodeC );
nodeC.setValue( 55 );
System.out.println("nodeC: " + nodeC );
}
}
To compile and run it, ensure that GenericNodeTester.java and GenericNode.java
are in the same subdirectory (or part of the same project):
PS C:\Code> javac -Xdiags:verbose GenericNodeTester.java PS C:\Code> java GenericNodeTester nodeA: 5.5 nodeA: 5.0 nodeB: Good Dog Carl nodeB: The Cat in the Hat nodeC: 45 nodeC: 55 PS C:\Code>
The switch -Xdiags:verbose asks the compiler to print out verbose error messages.
What do you expect this will print?
public class GenericNodeTester
{
public static void main (String args[])
{
GenericNode<Integer> nodeA = new GenericNode<Integer>( 5.5 );
System.out.println("nodeA: " + nodeA );
}
}