title: How to only allow certain values as parameter for a method in Java?
body: <p>I want to write a method that only takes certain values for a parameter, like f.e. in the <code>Toast</code> class in Android. You can only use <code>Toast.LENGTH_SHORT</code> or <code>Toast.LENGTH_LONG</code> as duration for the method <code>makeText(Context context, int resId, int duration)</code>. I had a look at the source code of the <code>Toast</code> class but found nothing there. How can I achieve that? </p>