Here you can find the source of setOnly(EnumSet
public static <E extends Enum<E>> EnumSet<E> setOnly(EnumSet<E> theSet, E flag)
//package com.java2s; /*/*from ww w. j av a 2 s. c o m*/ * Copyright (C) 2009 Emweb bvba, Leuven, Belgium. * * See the LICENSE file for terms of use. */ import java.util.EnumSet; public class Main { public static <E extends Enum<E>> EnumSet<E> setOnly(EnumSet<E> theSet, E flag) { theSet.clear(); theSet.add(flag); return theSet; } }