avatar
50luxA + 35cronA $5000?# PhotoGear - 摄影器材
g*a
1
要是坑,太牛掰了,浪费这么多人感情。也不见楼主护坑。就发了两个贴。
avatar
z*5
2
已知:
class Animal{}
class Dog extends Animal{
void bark();
}
需要实现下面这个函数
void makeTheDogsBark(List animals){
}
要求用java type cast实现,且不能用try catch。。。。
avatar
n*s
3
严峻考虑ing
avatar
e*a
4
void makeTheDogsBark(List animals){
((Dog) animals.get(0)).bark();
}
java generics is tricky
avatar
b*a
5
这还犹豫?
avatar
z*5
6
谢谢解答。请问如果我的animals的第一个是cat,Type cast dog会throw exception吗
?我自己在eclipse上实验了一下,好像也会有exception。
今天这个面试算是考到我的知识盲点了。

【在 e***a 的大作中提到】
: void makeTheDogsBark(List animals){
: ((Dog) animals.get(0)).bark();
: }
: java generics is tricky

avatar
d*o
7
这又什么好犹豫的,回头出任何一个不喜欢的就行了
avatar
b*0
8
用instanceof?这样不是dog的animal的其它子类对象可以忽略
avatar
r*x
9
这还考虑啥子哦。。。

【在 n*****s 的大作中提到】
: 严峻考虑ing
avatar
m*g
10
void makeTheDogsBark(List animals){
for (Animal a : animals) {
if (a instanceof Dog) {
Dog d = (Dog) a;
d.bark();
}
}
}
avatar
n*s
11
最近花钱好多。。。

【在 r******x 的大作中提到】
: 这还考虑啥子哦。。。
avatar
z*5
12
这个应该是对的,instanceof 我从来没用过,惭愧
多谢解答。

【在 m*****g 的大作中提到】
: void makeTheDogsBark(List animals){
: for (Animal a : animals) {
: if (a instanceof Dog) {
: Dog d = (Dog) a;
: d.bark();
: }
: }
: }

avatar
x5
13
新孩在想能不能砍到3000

【在 r******x 的大作中提到】
: 这还考虑啥子哦。。。
avatar
c*t
14
Reflection或许也可
void makeTheDogsBark(List animals){
for(Animal animal : animals) {
if(animal.getClass() == Dog.class) {
Dog dog = (Dog) animal;
dog.bark();
}
}
}
不知道对不对,欢迎指导
avatar
r*x
15
你买来直接出了还有得赚。。。

【在 n*****s 的大作中提到】
: 最近花钱好多。。。
avatar
w*z
16
谁工作中写这种玩意,一脚踹死。

【在 z***5 的大作中提到】
: 已知:
: class Animal{}
: class Dog extends Animal{
: void bark();
: }
: 需要实现下面这个函数
: void makeTheDogsBark(List animals){
: }
: 要求用java type cast实现,且不能用try catch。。。。

avatar
r*x
17
那我就去吐血。。

【在 x5 的大作中提到】
: 新孩在想能不能砍到3000
avatar
z*5
18
对,这个也可以,我当时没想起来。

【在 c**********t 的大作中提到】
: Reflection或许也可
: void makeTheDogsBark(List animals){
: for(Animal animal : animals) {
: if(animal.getClass() == Dog.class) {
: Dog dog = (Dog) animal;
: dog.bark();
: }
: }
: }
: 不知道对不对,欢迎指导

avatar
n*s
19
砍到3000我就不敢买了。。。

【在 x5 的大作中提到】
: 新孩在想能不能砍到3000
avatar
z*5
20
忘说了,这是G家面经。

【在 w**z 的大作中提到】
: 谁工作中写这种玩意,一脚踹死。
avatar
h*g
21
all in

【在 n*****s 的大作中提到】
: 严峻考虑ing
avatar
w*z
22
G 家用Java?

【在 z***5 的大作中提到】
: 忘说了,这是G家面经。
avatar
x5
23
你要吐血我们全得去卖肾了

【在 r******x 的大作中提到】
: 那我就去吐血。。
avatar
b*5
24
别搞了, 工作时, reflection, intanceOf都用吧, 你他妈的create 一个 log4j在
一个class里, 就用XXX.class...

【在 w**z 的大作中提到】
: 谁工作中写这种玩意,一脚踹死。
avatar
h*g
25
欢迎吐血,绝不卖肾

【在 x5 的大作中提到】
: 你要吐血我们全得去卖肾了
avatar
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...

avatar
r*x
27
吐血还能恢复,肾卖了就没了。。。

【在 x5 的大作中提到】
: 你要吐血我们全得去卖肾了
avatar
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.

avatar
X*U
29
您的意思是
您来吐口血,让版二来割肾?
太黑拉

【在 r******x 的大作中提到】
: 吐血还能恢复,肾卖了就没了。。。
avatar
g*g
30
This is not reflection, it's just passing a unique identifier so later on
Class.getName() can be used.

【在 b**********5 的大作中提到】
: protected static final Logger logger = LoggerFactory.getLogger(XXX.class)
: XXX.class is reflection...

avatar
h*g
31
有歧义,谁割谁的肾?

【在 X*U 的大作中提到】
: 您的意思是
: 您来吐口血,让版二来割肾?
: 太黑拉

avatar
b*5
32
hmm.. are u saying that for all calls to XXX.class, it's not reflection?

【在 g*****g 的大作中提到】
: This is not reflection, it's just passing a unique identifier so later on
: Class.getName() can be used.

avatar
r*x
33
我的意思是还是别卖肾了,来点可持续发展的

【在 X*U 的大作中提到】
: 您的意思是
: 您来吐口血,让版二来割肾?
: 太黑拉

avatar
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?
avatar
n*s
35
少生儿子多种树

【在 r******x 的大作中提到】
: 我的意思是还是别卖肾了,来点可持续发展的
avatar
X*U
36
割再生的吧
反正他可以再生

【在 h******g 的大作中提到】
: 有歧义,谁割谁的肾?
avatar
H*s
37
卖了一个肾还有另外一个肾下次还可以再卖一个。

【在 r******x 的大作中提到】
: 我的意思是还是别卖肾了,来点可持续发展的
avatar
a*9
38
上吧。。一个50lux医院里都奔这个数了。
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。