Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Generic Syntax Problem - class does not take any parameters

Hi! I recently encountered a small problem in this code, not sure what's wrong, but perhaps you guys could answer it.

interface interfaceOne<M>{
    public void methodOne(M insert); 
}

interface interfaceTwo<K>{
    public void methodTwo();
}

public class HelloWorld implements interfaceOne<String>{
    String stringVar = "Hello";
    public void methodOne(String stringVar){}


     public static void main(String []args){
        System.out.println("Hello World");
        interfaceOne<String> newObj = new HelloWorld<String>();
     }
}

1 Answer

The class itself isn't generic. You've already specified the type for the generic interface when you declared the class. Because of this, you don't need to use the angle brackets on new HelloWorld<String>(); Just new HelloWorld();