如何只允许某些值作为Java中方法的参数? [英] How to only allow certain values as parameter for a method in Java?
本文介绍了如何只允许某些值作为Java中方法的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想写一个只接受参数某些值的方法,例如f.e.在Android的Toast
类中.您只能将Toast.LENGTH_SHORT
或Toast.LENGTH_LONG
用作方法makeText(Context context, int resId, int duration)
的持续时间.我看了Toast
类的源代码,但是什么都没找到.我该如何实现?
I want to write a method that only takes certain values for a parameter, like f.e. in the Toast
class in Android. You can only use Toast.LENGTH_SHORT
or Toast.LENGTH_LONG
as duration for the method makeText(Context context, int resId, int duration)
. I had a look at the source code of the Toast
class but found nothing there. How can I achieve that?
推荐答案
查看全文