Generic method with no parameter

generics, java

Solution

Usually, the type is inferred, but you can specify the type with this syntax:

Note: You have an error in your method's definition - it had no return type:

private <T> TableCell<T> createTableCell(){
    return new TableCell<T>();
}

Here's how you can call it:

TableCell<SomeType> tableCell = myObject.<SomeType>createTableCell();

If you method doesn't access any fields, consider making it a `static` method, which you would call like:

TableCell<SomeType> tableCell = MyClass.<SomeType>createTableCell();

As an aside, when you use this syntax, many will marvel at your "eliteness" - it's a syntax not often seen.

Problem

I create a generic method without parameter, some thing like: ``` private <T> TableCell<T> createTableCell(){ return new TableCell<T>(); } ``` So, in my program, how to call this method for a concrete type?

Original source

Related problems