I have forgotten the syntax for a generic method:
public static void swap <T> (T a, T b)
{...}
And I don't find anywhere some example.What's the correct syntax?
Here I have written a sample piece which i have used for my application. You can get an idea from this.
public <C>void addColumn(Cell<C> cell, String headerText,
final GetValue<C> getter, FieldUpdater<DocumentType, C> fieldUpdater) {
Column<DocumentType, C> column = new Column<DocumentType, C>(cell) {
@Override
public C getValue(DocumentType object) {
return getter.getValue(object);
}
};
column.setFieldUpdater(fieldUpdater);
column.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
getTable().addColumn(column, headerText);
getTable().setColumnWidth(column, 10, Unit.PX);
}
static <T> void swap(T a, T b) {..}
You have to declare your typed parameters before the return type (void in your case).
http://docs.oracle.com/javase/specs/jls/se5.0/html/classes.html#8.4 (see TypeParameters )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.