由买买提看人间百态

topics

全部话题 - 话题: downcast
1 (共1页)
a*********e
发帖数: 697
1
来自主题: Programming版 - 一个java class downcast 的问题
看书时好像没注意,忽然觉得不明白了。
superclass
class A {
array m_arry[];
init(array); //to init m_arry
}
subclass
class B {
sort(this.m_arry);
}
main(){
A a;
B b=(B)a;
b.sort();
}
这样写把super class 对象downcast成subclass 的对象是会有问题的。调用b.sort()
是会出错,还是不出错但sort只是作用在b自己的m_arry上? 如果写:
b.init(a.m_arry);
b.sort();
是否就可以了?
s*******d
发帖数: 59
2
来自主题: Programming版 - 一个java class downcast 的问题
this downcast will raise exception
L*********r
发帖数: 92
3
来自主题: Programming版 - 一个java class downcast 的问题
Downcast is related to object instance.
You can do it as follwoing:
A a = new B;
B b = (B)a;
b.sort;
e*****t
发帖数: 1
4
来自主题: Programming版 - 一个java class downcast 的问题
Downcast is for Compile-time type check, i.e., for the compilers to do error
checking. For example, if you declare a class A and then point it to a Run-
time type B like the following,
Class A{
A(); //ctor
int a;
}
Class B extends A{
super();
sort();
}
A a = new B();
You can not say
a.sort(); //compile error
But you can say
(B)a.sort(); //compile OK
====
if you say
A a = new A();
B b = a;
you will get a compile error.
=======
if you say
A a = new A();
B b = new B();
a = b; // this is OK.
a.sort
L*********r
发帖数: 92
5
来自主题: Programming版 - 一个java class downcast 的问题
你应该理解一下下面的rules in java.
1.The rules for a casting from compile-time reference type S to a compile-
time reference type T are as follows:
If S is a class type:
If T is a class type, then either |S| <: |T|, or |T| <: |S|; otherwise a
compile-time error occurs.
2.
If a cast to a reference type is not a compile-time error, there are several
cases:
The cast is a checked cast. Such a cast requires a run-time validity check.
downcast follows the above 2 rules.

error
Run-
G******e
发帖数: 9567
6
来自主题: TrustInJesus版 - 什么是义?
如果儿子献的礼物不合老爸的意,那还能叫“义”吗?
创世记4:
3 In the course of time Cain brought some of the fruits of the soil as an offering to the LORD.
4 But Abel brought fat portions from some of the firstborn of his flock. The LORD looked with favor on Abel and his offering,
5 but on Cain and his offering he did not look with favor. So Cain was very angry, and his face was downcast.
6 Then the LORD said to Cain, "Why are you angry? Why is your face downcast?
7 If you do what is right, will you not be accepted?
w******d
发帖数: 1301
7
来自主题: TrustInJesus版 - 什么是义?
亚伯的问题是, 他因为耶和华看不中他的供物而发怒。
如果儿子献礼物给老爸表孝心, 结果却因为老爸不喜欢他的礼物而发怒。
这样的儿子是孝顺么? 这搁中国的传统也是不对的吧。

offering to the LORD.
The LORD looked with favor on Abel and his offering,
very angry, and his face was downcast.
downcast?
what is right, sin is crouching at your door; it desires to have you, but
you must master it."
L******N
发帖数: 1858
8
来自主题: TrustInJesus版 - 什么是义?
5 只是看不中该隐和他的供物。
5 but on Cain and his offering he did not look with favor.
不合神的心意的是“该隐”和“他的供物”;而不仅仅是他的供物。更不是因为他的供
物的问题,导致神不喜悦他。
关于供物的问题,在后面申命记里有交代,要把出产里面最好的献给神。
在神没有定下这些献祭的律法之前,亚伯就知道把自己的羊群里的最好的——头生的羊
和羊的脂油献上,将最好的献上,这是出于爱和愿意亲近的心;而该隐献上的只是地里
的出产,如果他有亚伯那样的心意,他应该将初熟的土产献上为礼物(申26:2),至少
不应该是just brought “some”of the fruits of the soil。

offering to the LORD.
The LORD looked with favor on Abel and his offering,
very angry, and his face was downcast.
downcast?
what is right, sin is crouching at you
w*******g
发帖数: 9932
9
来自主题: Java版 - [转载] Java 1.5 Generic 问题
whenever you have downcast in Java, it will have dynamic checks.
If you use generic consistently, there are very few places you need downcast.
x****u
发帖数: 44466
10
来自主题: Programming版 - 国内的编程论坛很不自由
你这阅读真连那2b版主都不如,人家也看懂我没否认static_cast可以做downcasting,
只是一口咬定downcasting是安全操作。
C/C++所有导致编译不过去的东西都是安全的,危险指的是可能编译通过可能运行但行
为不确定。如果你找ONS失败,不管准备了套没有都肯定不会得艾滋,明白了?
n****n
发帖数: 222
11
来自主题: Programming版 - swift用了一个月有感
是的我就是downcast的时候。Swift读restful API的时候不知道data类型是什么,我只
能一步一步downcast,最好还要加上 if let,以防万一类型cast错了,或者API改了
response。
s**x
发帖数: 7506
12
来自主题: JobHunting版 - 问一个c++ virtual base class的问题
你好像把 downcast/upcast 搞反了。
f**********w
发帖数: 93
13
来自主题: JobHunting版 - one C++ question?
如果基类没有任何virtualmethod, 为什么要做指针的转换呢?这种情况不存在任何的
多态,在我看来,错误应该是指针转换本身,而不是有或没有virtual destructor。举
个例子
如果我们在derived class 里定义了一个新的method,如果我们把指针转换成基类指针
,然后用基类指针调用derived class method,一样会导致错误。The responsibility
is on the client side to make sure they do not do downcast if base class
does not contain any virtual method.
x*****p
发帖数: 1707
14
来自主题: JobHunting版 - 实践问题一个
In Java, you can use instanceof keyword to check whether the instance is a D
, then do downcasting if it is.
In C++, it should provide a similar way to do it.
w********9
发帖数: 8613
15
来自主题: Parenting版 - 英文 委屈 怎么说?
可以用depressed, dejected, or downcast来直接表达“委屈”所含的一个主要成份。
r****n
发帖数: 179
16
zz4
今天,2014年2月6日,Satya上任后的两天,财经新闻充满了关于一个SAC资本对冲基金
经理被判内线交易,证券诈骗有罪的报道。
这个对冲基金经理名叫Mathew Martoma。乍一看之下似乎是南欧或者南美人。实际上,
这哥们是
道地的印度人,原名Ajai Mathew Mariamdani Thomas。Ajai 是咋变成Mathew Martoma
的泥?
原来这里另有一段佳话,让篡改简历的IT老印都自愧不如,至于琐男们,我不知道尔等
是何感想:
Ajai原来是哈佛法学院的学生。快毕业找工作时,Ajai非法黑进哈佛管理成绩的数据库
,改高了自己几门课的分数,随后把这些成绩发给了他正在申请职位的几个法院。
聪明伶俐的Ajai如愿以偿拿到了一所法院的职位。但是,DC法院的工作人员鬼使神差地
觉得Ajai成绩单可能有诈,就联系了哈佛。
Ajai得知此事,立刻干了两件事:
1。告知哈佛自己攻入学校计算机,篡改了成绩。但是他说这只是为了给他父母看,并
没有想到成绩被发给了法院。
2。写了一封电子邮件,邮件里告知法学院秘书千万不要把自己的成绩寄给他在申请的
法院。Ajai 把Ema... 阅读全帖
l*****9
发帖数: 9501
17
Jeremy Lin on His Fast Break to Fame, God, and Kobe Bryant
By Jeff Yang
When The Garden is full and the right moment hits, it sounds like a riverbed
canyon during spring thaw. The roar is deafening, and it rebounds from wall
to wall, off the rafters, and into your face with tangible force.
The first time you felt that sonic boom was a few minutes into last night’s
program, when No. 17, Jeremy Lin — the man of the hour, the evening and
just maybe the season — trotted into the strobing lights of t... 阅读全帖
w***7
发帖数: 5568
18
本赛季结束后的8个HC和5个GM职位全部雇佣了白人,蛋鸡对此结果非常不满。
http://sportsillustrated.cnn.com/nfl/news/20130121/peter-king-m
I spoke to one high-ranking team executive late Friday, after eight NFL
coaching vacancies, five GM vacancies and one vice president of player
personnel slot were filled -- all by white men. "Shocking,'' he said. "One
by one they get filled, and you don't realize what happened until it's over,
but that's not good for our league. Not good."
"I don't know what the answer is,'' a downcast Tony Dung... 阅读全帖
a*****g
发帖数: 19398
19
来自主题: Go版 - The worst Go player(转载)
The worst Go player(转载)
I live with a guy who is just the worst Go player. He's terrible! As much as
I try and teach him, he seems to keep making the same dumb mistakes. I got
so annoyed that I made a list of his faults:
He misses obvious ataris and gets his groups killed
He misses obvious threats such as double ataris and snapbacks
He continually misreads simple life and death situations
His groups get killed when they should live because he missed a vital
point
He fails to ... 阅读全帖
i**y
发帖数: 829
20
刚刚关于该飞机再次算了一次(是总的第二次),结果如下:
Question:Is THE plane Flight 370 in the ocean?
『牌阵名称』:圣三角
◎使用【偉特牌普及版】占卜◎
◎使用78张占卜◎
◎底牌是【金币3】【正位置↑】◎
◎不使用象征指示牌◎
────────────────
1==过去
【圣杯5】【正位置↑】
------------------------------------------------
2==现在
【权杖9】【逆位置↓】
------------------------------------------------
3==未来
【恋人】【正位置↑】
------------------------------------------------
●●●统计表●●●
正位2张   逆位1张
大牌1张
宝剑0张
权杖1张
圣杯1张
金币0张
------------------------------------------------
尝试解读:
最重要的大牌出现在【未来】 是关于duality,阴阳,循环,【过去】已经是 完成时... 阅读全帖
s******l
发帖数: 278
21
来自主题: SciFiction版 - Dune book 3 - 10
And Muad'Dib stood before them, and he said: "Though we deem
the captive dead, yet does she live. For her seed is my seed
and her voice is my voice. And she sees unto the farthest
reaches of possibility. Yea, unto the vale of the unknowable
does she see because of me."
-from "Arrakis Awakening" by the Princess Irulan
The Baron Vladimir Harkonnen stood with eyes downcast in
the Imperial audience chamber, the oval selamlik within the
Padishah Emperor's hutment. With covert glances, the Baron
h
a*********d
发帖数: 2763
22
来自主题: Translation版 - 原创及翻译: 竹蝴蝶
很久以前写的小文,朋友翻译了一下,和大家分享。我的专业是甲状腺疾病,很久以前
听说
过一个故事,所以写下来。
===============
“竹叶飒飒轻舞,小溪叮咚伴唱。竹林深处深处,笛声婉转悠扬……”
Bamboo leaves dancing in the wind, little creek accompanies with song. In
the depth of the bamboo forest, the flute sounds smooth and melodious.
这是我家乡的山歌,我从小就会唱。我出生的那个村子,非常美丽,被重重叠叠的青黛
山峦包围,有缓缓流淌的湖水,有一望无际的竹林。我的爷爷,爹爹和哥哥们,从没有
人走出过这个竹林,世世代代,在这里耕火相传,安详地生活着。
This is the mountain song of my home. I was able to sing it when I was young
. The village of my birth, a very beautiful place, surrounded by ... 阅读全帖
B**T
发帖数: 294
23
来自主题: TrustInJesus版 - 耶稣复活始末
Jesus’ First Resurrection Appearance:
Mark 16:14-15 - Jesus appears to Mary Magdalena but it’s not clear where (
in older endings of Mark, he didn’t appear at all)
Matthew 28:8-9 - Jesus first appears near his tomb
Luke 24:13-15 - Jesus first appears near Emmaus, several miles from
Jerusalem
John 20:13-14 - Jesus first appears at his tomb
Jesus Ascends to Heaven:
Mark 16:14-19 - Jesus ascends while he and his disciples are seated at a
table in or near Jerusalem
Luke 24:50-51 - Jesus ascends outi... 阅读全帖
d****o
发帖数: 32610
24
来自主题: Apple版 - 请推荐iOS上好用的podcast app
downcast
d****o
发帖数: 32610
25
来自主题: Apple版 - 请推荐听新闻的app
听podcast就好了啊
downcast很好用
m******t
发帖数: 2416
26

I'm sorry, I didn't realize you were using Clob.setString() already.
Never mind the second question.
I remember Oracle has some weird way of handling clobs and blobs. Last time I
had to do this, I had to downcast the drive to the oracle driver class and
call some proprietary methods on it. And that was around JDK 1.3.1 or so...
m******t
发帖数: 2416
27
来自主题: Java版 - [转载] Java 1.5 Generic 问题

I don't think you can get rid of the warning - as long as you keep
using HashMap. If you are sure all the values
are going to be HashMap, you can do:
HashMap>
which will prevent the warning.
Otherwise, the best the compiler knows about your value type at
retrieval time is that it's an Object, and when you downcast it,
the compiler will always give a warning.
T*******x
发帖数: 8565
28
来自主题: Java版 - [转载] Java 1.5 Generic 问题
Object obj = new Object();
Integer integer = (Integer) obj;
String string = (String) obj;
HashMap map = (HashMap) obj;
HashMap stringMap = (HashMap) obj;
以上的4个cast,只有最后一个给出warning,为什么?

downcast.
g*****g
发帖数: 34805
29
来自主题: Programming版 - 一个java class downcast 的问题

error
Run-
will have compile error, ((B)a).sort() is fine,
a*********e
发帖数: 697
30
来自主题: Programming版 - 一个java class downcast 的问题
是的,我在编译器里自己写了一遍结果就出现exception了。
多谢各位指点!
还有一点疑问,如果我已经有了A的对象a,并且已经初始化了m_arrary,
A a=new A();
a.m_array=...;
我想再定义一个有sort功能的扩展类B的对象b,并让它具有a中的m_array值该怎么操作?
这时是不能用的:
B b=(B)a;
也不能重新定义:
A a=new B();
最好的实现方法是不是定义一个B的constructor,用A类型对象作为参数,把m_array的
元素一一复制一遍?
B (A a){
this.m_array[]=a.m_array[];
}
再调用:
B b=new B(a);
g*****g
发帖数: 34805
31
来自主题: Programming版 - 一个java class downcast 的问题
Either make m_array protected, or make it private
and have a getter. BTW, m_array is not naming convention for java.

作?
a*********e
发帖数: 697
32
来自主题: Programming版 - 一个java class downcast 的问题
Yes, I know the unstandard naming.
sorry, I didn't get you. What's the matter of "private" or "protect" with
using B b's member array and sorting?
f******n
发帖数: 90
33
来自主题: Programming版 - C++ cast 小结
最近研究了一下cast, 成果如下,大家看看如何:
const_cast:
It's only used to add or remove qualifiers: const or volatile. Note: static
_cast can add const and can never remove const.
reinterpret_cast:
It never does any check, neither compile time nor runtime. But it requires
the two types have the same storage size in memory.
static_cast VS dynamic_cast:
In the inheritance hierarchy (all public inheritance), upcast will always
work, even without any type of explicit cast. static_cast will work for
downcast too wi
a*******s
发帖数: 324
34
来自主题: Programming版 - C++ cast 小结
for the upcast, do you mean derived --->base?
downcast, base-->derived?
Thanks,
a*******s
发帖数: 324
35
来自主题: Programming版 - C++ 弱问一个
It seems that for the upcast, there is no need to use static_cast.
but for the downcast. it must.
B* p = &c; //ok
B* p = static_cast(&c) //ok
C* p = &b; //error
C* p = static_cast(&b) //ok
anyone explain it?
P*****f
发帖数: 2272
36
来自主题: Programming版 - dynamic_cast operator in C++
Besides downcast,
dynamic_cast is also used to support "cross cast" in MI.

To make it a valid dynamic_cast, B should be descendant of A.
The object pointed by ap should be an object of B or B's descendant.
of
c****l
发帖数: 1280
37
来自主题: Programming版 - c++ question, thanks
1. multiple inheritance with mixed virtual inheritance and non-virtual
inheritance
2. When you do upcasting and downcasting, should the object pointer be equal
for the base class and derived class, or should there be an offset shift?
z****e
发帖数: 2024
38
来自主题: Programming版 - A C++ compiler related interview question
no, it will not compile, because bar is not virtual and vptr can not lookup the vtable and find it. so it should fail. bar is not even a member of base.
actually, even bar() is virtual but added by Derived, through base class pointer to call it, is a compile time error. you can downcast using
dynamic_cast(p)->bar() to finish the call.
s*******e
发帖数: 27
39
来自主题: Programming版 - A C++ compiler related interview question
Thanks a lot.

lookup the vtable and find it. so it should fail. bar is not even a member
of base.
pointer to call it, is a compile time error. you can downcast using
d****p
发帖数: 685
40
Yes. There is always a type check before applying any form of cast (implicit
, c style, static, dynamic,
reinterpret).
In your case it is a downcast (Base* -> Derived*) so it could not be
implicit.
t****t
发帖数: 6806
41
来自主题: Programming版 - reading STL list implementation
往上看几行, 有注释:
// Supporting structures are split into common and templated
// types; the latter publicly inherits from the former in an
// effort to reduce code duplication. This results in some
// "needless" static_cast'ing later on, but it's all safe
// downcasting.
/// Common part of a node in the %list.
那意思就是说, 模板化的没办法, 必须得给你代码才能编译, 没有模板, 对性能影响又
不大的, 就给你预编译好了, 省得每次编译.
libstdc++.so, 里面就是这些代码了. 你要看源代码, 自己下载一个就可以了.

_
x****u
发帖数: 44466
42
来自主题: Programming版 - 国内的编程论坛很不自由
禁了rtti也不该用static_cast做downcast或者sidecast,可以试试类似COM的做法。
dynamic_cast的最大意义是容许文雅的转换失败。

cast了
x****u
发帖数: 44466
43
来自主题: Programming版 - 国内的编程论坛很不自由
你们跟谭浩强老爷爷学C++的时候没听说过不让做和编译不过是两回事么?
你还是赶紧水木去学C++,不要来这里打滚丢人了。

downcasting,
但行
z****e
发帖数: 54598
44
来自主题: Programming版 - swift用了一个月有感
?不用改成!,这两个mutually exclusive
只有as的downcast时候才必需改成as!
这个功能只有用xcode时候才能提高编程效率
如果不用ide,用vi这里肯定疯狂拉低编程效率
说到底还是要学会用ide
g*****g
发帖数: 34805
45
来自主题: Programming版 - 捏着鼻子看scala b编程pattern
Pattern matching is a rarely used feature at best. If you downcast a lot,
the design must be wrong.
c********l
发帖数: 8138
46
来自主题: Quant版 - 墙街大阿三被捉拿归案
Former SAC Manager Mathew Martoma Found Guilty in Insider Case
By CHRISTOPHER M. MATTHEWS And JOHN CARREYROU
Updated Feb. 6, 2014 3:49 p.m. ET
Mathew Martoma, a former SAC Capital Advisors portfolio manager, leaves
federal court in New York on Thursday with his wife, Rosemary. A jury
Thursday convicted Mr. Martoma of insider trading. Bloomberg News
A jury found former SAC Capital Advisors LP portfolio manager Mathew Martoma
guilty of insider trading, a verdict that burnishes prosecutors' virtual... 阅读全帖
a*********d
发帖数: 2763
47
来自主题: Medicalpractice版 - 原创小说及翻译--竹蝴蝶
很久以前写的小文,朋友翻译了一下,和大家分享。我的专业是甲状腺疾病,很久以前
听说过一个故事,所以写下来。
===============
“竹叶飒飒轻舞,小溪叮咚伴唱。竹林深处深处,笛声婉转悠扬……”
Bamboo leaves dancing in the wind, little creek accompanies with song. In
the depth of the bamboo forest, the flute sounds smooth and melodious.
这是我家乡的山歌,我从小就会唱。我出生的那个村子,非常美丽,被重重叠叠的青黛
山峦包围,有缓缓流淌的湖水,有一望无际的竹林。我的爷爷,爹爹和哥哥们,从没有
人走出过这个竹林,世世代代,在这里耕火相传,安详地生活着。
This is the mountain song of my home. I was able to sing it when I was young
. The village of my birth, a very beautiful place, surrounded by l... 阅读全帖
1 (共1页)