z*5
2 楼
已知:
class Animal{}
class Dog extends Animal{
void bark();
}
需要实现下面这个函数
void makeTheDogsBark(List animals){
}
要求用java type cast实现,且不能用try catch。。。。
class Animal{}
class Dog extends Animal{
void bark();
}
需要实现下面这个函数
void makeTheDogsBark(List
}
要求用java type cast实现,且不能用try catch。。。。
n*s
3 楼
严峻考虑ing
e*a
4 楼
void makeTheDogsBark(List animals){
((Dog) animals.get(0)).bark();
}
java generics is tricky
((Dog) animals.get(0)).bark();
}
java generics is tricky
b*a
5 楼
这还犹豫?
d*o
7 楼
这又什么好犹豫的,回头出任何一个不喜欢的就行了
b*0
8 楼
用instanceof?这样不是dog的animal的其它子类对象可以忽略
m*g
10 楼
void makeTheDogsBark(List animals){
for (Animal a : animals) {
if (a instanceof Dog) {
Dog d = (Dog) a;
d.bark();
}
}
}
for (Animal a : animals) {
if (a instanceof Dog) {
Dog d = (Dog) a;
d.bark();
}
}
}
c*t
14 楼
Reflection或许也可
void makeTheDogsBark(List animals){
for(Animal animal : animals) {
if(animal.getClass() == Dog.class) {
Dog dog = (Dog) animal;
dog.bark();
}
}
}
不知道对不对,欢迎指导
void makeTheDogsBark(List
for(Animal animal : animals) {
if(animal.getClass() == Dog.class) {
Dog dog = (Dog) animal;
dog.bark();
}
}
}
不知道对不对,欢迎指导
w*z
26 楼
你看懂题没有?which one is reflection here?
http://www.mkyong.com/logging/log4j-hello-world-example/
logger final static initialized once only.
【在 b**********5 的大作中提到】
: 别搞了, 工作时, reflection, intanceOf都用吧, 你他妈的create 一个 log4j在
: 一个class里, 就用XXX.class...
http://www.mkyong.com/logging/log4j-hello-world-example/
logger final static initialized once only.
【在 b**********5 的大作中提到】
: 别搞了, 工作时, reflection, intanceOf都用吧, 你他妈的create 一个 log4j在
: 一个class里, 就用XXX.class...
b*5
28 楼
protected static final Logger logger = LoggerFactory.getLogger(XXX.class)
XXX.class is reflection...
【在 w**z 的大作中提到】
: 你看懂题没有?which one is reflection here?
: http://www.mkyong.com/logging/log4j-hello-world-example/
: logger final static initialized once only.
XXX.class is reflection...
【在 w**z 的大作中提到】
: 你看懂题没有?which one is reflection here?
: http://www.mkyong.com/logging/log4j-hello-world-example/
: logger final static initialized once only.
g*g
34 楼
It's pointless to argue the term. I wouldn't call it reflection when no
instance for the passed class is created. The static class information is
always available in
Class API. It's more like a shortcut way to pass a fully qualified class
name in String. The point is that all these information are already
available at compile time.
【在 b**********5 的大作中提到】
: hmm.. are u saying that for all calls to XXX.class, it's not reflection?
instance for the passed class is created. The static class information is
always available in
Class API. It's more like a shortcut way to pass a fully qualified class
name in String. The point is that all these information are already
available at compile time.
【在 b**********5 的大作中提到】
: hmm.. are u saying that for all calls to XXX.class, it's not reflection?
a*9
38 楼
上吧。。一个50lux医院里都奔这个数了。
相关阅读
Pentax FA31 on Sony NEX7头痛 百刀坑的5d3x18的六百多刀该买什么18个shopper,攒人品其实吧,这个聘教授要博士学位本身就很扯淡10x buy.com today, any printer recommend?百刀坑上D800E卖的真快,等关paddy 20X搭车问,SUV有没有能在里面睡觉的?[合集] 继续奔,AF小碎花裙 (转载)请教一个革命鸡的问题35mmf/2多少米可以收amazon 的赵亚伦是板上的不?P+稳居本版的第三大帮了啊100$的gitzo gm2540 monopod+bogen3329要不要AGFA的卷儿颜色很惊艳啊。。。小调查:你最多做过几层梦LOCAL哪些店CARRY革命机我这样做到底对不对老婆问如果我在车子里面被水淹打不开门窗怎么办?x100总算平安地从我手上过去了友情提示:10X有D4, Big Value Inc.