java - 通用方法语法

我忘记了通用方法的语法:

public static void swap <T> (T a, T b)
{...}


我在任何地方都找不到示例,正确的语法是什么?

最佳答案

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);
    }