先学习C/C++转而学习JAVA的朋友可能觉得JAVA没有enum类型很不方便. 这个问题其实可以通过Interface来解决:
比如定义一个Interface:
public interface Animal
{
int DOG = 1, CAT = 2, TIGER =3, SNAKE = 4;
}
public class Test implements Animal
{
public Test();
public boolean isDog( int animal)
{
return (animal == DOG) ? true : false;
}
}
对于先学C/C++再学Java的人,会觉得Java没有enum类型不方便。可通过Interface解决该问题,如定义一个Interface包含动物常量,再用类实现该Interface,并编写判断方法。
214

被折叠的 条评论
为什么被折叠?



