r****n 发帖数: 1088 | 1 you can't get generic type in runtime because of the type erasure, so that
java can be backward compatible. |
|
r****n 发帖数: 1088 | 2 you can't get generic type in runtime because of the type erasure, so that
java can be backward compatible. |
|
g*****g 发帖数: 34805 | 3 Since Java uses type erasure, generics is a compile time trick.
If it can't decide the type in compile time, it can't do instantiation.
template
the |
|
l*********s 发帖数: 5409 | 4 java's type erasure is very confusing. The shear number of design
patterns/frameworks is also daunting. |
|
l*********s 发帖数: 5409 | 5 yes, overall Java is much more friendly. but there is some aspect like type
erasure/generic very difficult to get used to for C++ programmers. |
|
l*********s 发帖数: 5409 | 6 it looks similar, but type erasure is just terrible. |
|
l*********s 发帖数: 5409 | 7 Long is final, extends Long does not make senses. and the type erasure only
grantees that reading from T will be legit, the T could hold any thing
extends from Long, thus you run the risk of heterogeneity thus java
disallowed it. |
|
d****i 发帖数: 4809 | 8 一般的普通的class,可以通过MyClass.class得到,但是如果有Generics的情况,由于
type erasure,就没法得到它的class,比如我想用List.class,就会报错,
但是有些class method只接受这样的input argument:
public void foo(Class> class)
如果我想传入一个List的类的话,怎么办?没法用
foo(List.class) |
|
d****i 发帖数: 4809 | 9 You need to use the following to create a generic array. Java's generics has
type erasure, so you can't create generic array at compile-time since it
needs runtime info.
public static > void sort(T[] a, Class clazz) {
T[] tmp = (T[]) Array.newInstance(clazz, a.length);
}
Or you can just use ArrayList directly without the hassle. |
|
m********7 发帖数: 1368 | 10 type erasure! 这下大概明白为啥总报错了,谢谢热心的帮助! 哈!
has |
|
b********n 发帖数: 609 | 11 right, it's type erasure. I forgot it after so long. |
|
h*********o 发帖数: 62 | 12 Java generic is totally different from C++ template under hood. Does C++
use also sharing and type erasure when dealling template? If not, do you
see any problem/benefit to do the template in a way that Java does? Or why
didn't java use C++ template to do its generics? |
|
r*********r 发帖数: 3195 | 13 c++ uses type expansion. java uses type erasure. exactly opposite.
c++'s way may lead to code bloating.
but c++'s template uses integers as type parameters,
which makes the mechanism Turing complete. |
|
g*****g 发帖数: 34805 | 14 Type erasure doesn't make my job more difficult in real life.
It wasn't like Java community are crying loud for current
implementation. |
|
g*****g 发帖数: 34805 | 15 Barring functional, there's dynamic programming, asynchronicity,
parrllelism, generics I assume?
You can ask neverlearn about dynamic programming. I've talked about
asynchronicity. And I still think parrellelism should be takend care
by the compiler/VM. If that answers your question.
For generics, Java values back-compatiblity and it has to be done
by type erasure. Is it ideal? No, but enterprise developers hate
more the idea of throwing previous version under the bus approach
of .Net. It's stil... 阅读全帖 |
|
N********n 发帖数: 8363 | 16
就算抄袭也要抄考试答满分的,没听说过抄不及格的。
JAVA的GENERIC在TYPE系统上玩SHORT-CUT,靠Type Erasure投机取巧,做
出来一个JOKE,不及格水平,还以为C#会来抄?C#要是也象JAVA那样处理
GENERIC就做不出来LINQ了。 |
|
g*****g 发帖数: 34805 | 17 你就不懂Java做这个type erasure是为啥,是为了在字节码上
达到forward compatible。这个在.Net上完全没有,back-compatible
也是半吊子,完全符合微软的一贯形象。
forward compatible在某些enteprise应用很重要,因为各种原因runtime
不能升级,但仍然希望把一些新出现的库和功能添加到现有的系统上。
至于连back-compatible都不能保证更是没法说了。 |
|
n*w 发帖数: 3393 | 18 这个贴本来几天前就要发,当时看到有几个真正对程序语言principal有了解的人发了
不少贴。结果来了几个大坑。为了避嫌推迟到现在。
一直都scala的higher-kind type很好奇。scala是我知道两个支持higher kind type的
语言之一。另一个是haskell。有人要求microsoft在f#中加入,ms给出的答复是不会加
,因为要大改clr。
但jvm连first order都不支持。java的generic编译后要做type erasure。只是个
compiler trick。觉得scala的higher kind type要么同样也只是compile-time
checking,要么在jvm上加了东西?
找到这一段“Scala runs on the JVM, which implements a very poor type system
on its own (much poorer than the CLR). It doesn’t support type parameters
of any kind, let alone type const... 阅读全帖 |
|
n*w 发帖数: 3393 | 19 scala introduced manifests, 缓解了type erasure的部分问题?但performance
issue是不是还存在? |
|
n*w 发帖数: 3393 | 20 这个贴本来几天前就要发,当时看到有几个真正对程序语言principal有了解的人发了
不少贴。结果来了几个大坑。为了避嫌推迟到现在。
一直都scala的higher-kind type很好奇。scala是我知道两个支持higher kind type的
语言之一。另一个是haskell。有人要求microsoft在f#中加入,ms给出的答复是不会加
,因为要大改clr。
但jvm连first order都不支持。java的generic编译后要做type erasure。只是个
compiler trick。觉得scala的higher kind type要么同样也只是compile-time
checking,要么在jvm上加了东西?
找到这一段“Scala runs on the JVM, which implements a very poor type system
on its own (much poorer than the CLR). It doesn’t support type parameters
of any kind, let alone type const... 阅读全帖 |
|
n*w 发帖数: 3393 | 21 scala introduced manifests, 缓解了type erasure的部分问题?但performance
issue是不是还存在? |
|
n****1 发帖数: 1136 | 22 The author is plainly stupid. All his problem with Go can be attributed to
the lack of generics, so he choose java... good choice, except that:Java is
just doing type erasure!!!
He can simply declare a stub interface in Go and implement this interface in
all his 6 data types. Then write his generic functions only on this
interface, that is all java did. |
|
N********n 发帖数: 8363 | 23
啥难度啊?除钩子、亚麻能做自己CLOUD之外,其余哪家能和AZURE相比
啊?论技术难度ALEXA上那堆阿猫阿狗和PUBLIC CLOUD公司比差得远呢。
JAVA动辄CLASSPATH,JAR HELL的问题快20年了都没解决,一整就TYPE
ERASURE。设计得一塌糊涂,谁敢抄你啊? |
|
s***o 发帖数: 2191 | 24 不错。看到了新的希望。我正犹豫是不是dump scala,虽然想起java由于type erasure
导致的各种问题,以及无穷无尽的configuration就头晕眼花。
Scala还有play的backward compatibility 一直很成问题啊 |
|
N********n 发帖数: 8363 | 25
用JAVA GENERIC TYPE ERASURE时怎么没自杀? |
|
w***g 发帖数: 5958 | 26 C#跟basic屁关系都没有。C#的渊源是Borland和Anders Hejlsberg。C# UI designer
是从delphi一路相承的,能把java甩出去几条街。不可否认C#借鉴了java的一些特性,
但那都是表面现象。就语言讲C#是比java要牛B的。Java的generic用的是type erasure,
而C#则是在字节码层面实现的。不过语言牛B其实P用没有,还要看谁business弄得好。
当年MFC那么烂大家不都还照用。
不了解历史的可以读一下Borland传奇和当年的C++编译器争霸的故事,很有意思。
nt
在。 |
|
|
w**z 发帖数: 8232 | 28 Java generic 是不好,但那是后加的。要backward compatible, 没办法。Java 的用
户群太庞大,搞点改动太不容易。但同时也说明谁想取代Java/jvm 都不太可能。
erasure, |
|
|
x********q 发帖数: 108 | 30 嘴里不带口头禅就说不出话来?
我说的基因,是指一个公司产品文化的基因。谁看不出来vb除了能在clr上跑和c#没啥
关系?这里是说语言从来微软重要产品,也是靠这个起家的。就好像说search是Google
的基因,social media是Facebook的基因一样。
erasure, |
|
g****r 发帖数: 1589 | 31 差不多
不过开源届也没啥等量级的语言,所以虽然java就是一坨,大家也只能继续往上堆东西
,堆到最后轮子多了倒也成了优势
erasure, |
|
p*****2 发帖数: 21240 | 32 Scala's disjoint part has polymorphic sub-typing and implicit dictionaries.
Haskell's disjoint part has first-class type classes, type-level functions,
full type inference, and many other neat little tweaks. The intersection is
a higher-kinded type system with first-class functions.
Scala's part of the intersection, for a list of reasons that include JVM
type erasure, issues combining higher-kinded types with polymorphic sub-
typing, and certain implementation choices, is partially "broken" in t... 阅读全帖 |
|
p*****2 发帖数: 21240 | 33 Scala's disjoint part has polymorphic sub-typing and implicit dictionaries.
Haskell's disjoint part has first-class type classes, type-level functions,
full type inference, and many other neat little tweaks. The intersection is
a higher-kinded type system with first-class functions.
Scala's part of the intersection, for a list of reasons that include JVM
type erasure, issues combining higher-kinded types with polymorphic sub-
typing, and certain implementation choices, is partially "broken" in t... 阅读全帖 |
|
l******t 发帖数: 55733 | 34
,
is
use
Scala
其实Martin Odersky还是很清楚他要干什么的。听他的course收获很大。implicit和
partial function都是为了context injection,manifest/typetag是解决erasure的问
题,covariant是为了解决OO继承的anti pattern。这里面大概除了manifest其他都可
以opt out。可是架不住别人会用所以还是要懂。scala为了OO/jvm compromise太多。
如果能有选择肯定直接haskell。 |
|
N********n 发帖数: 8363 | 35
这啥玩意,手动挡TYPE ERASURE? OBJECT类型都拿出来了还咋DATA BINDING。是不
是JAVA GENERICS玩太多了?LOL |
|
|
N********n 发帖数: 8363 | 37 W/ generic OOP is able to decouple funcs from classes already. If it's
needed it's there. OOP funcs don't have to be bound to a class.
It just has to be a real generic like that of C#, rather than type
erasure garbage JAVA does. |
|
H****S 发帖数: 1359 | 38 最好也别用Java generics,欧洲学院派愚蠢设计,还有type erasure问题。Java从5开
始就是反人类的节奏。
open |
|
d****i 发帖数: 4809 | 39 你这个也太扯了,Java的泛型就是从C++ template而来,何来愚蠢? type erasure不
是问题,有反射就可以解决了。 |
|
w***g 发帖数: 5958 | 40 GC: immediate solution,表面上看似解决了问题,实际上只是部分
解决了问题,而且同时创造了不止一个新的问题。
RAII: 本质的解决方案,不止解决了内存分配一类问题(这个也是部分
解决),而且同时也解决了所有其他资源分配的问题。
从技术的角度上来说,我觉得这两者高下立判。看似都没有显式的
资源回收,前者是纵容用户,后者则是培养一种思维方式,写出来
的东西都是防患与未然的。就是代码写出来,也是C++的更简洁:
// C++
{
fstream out("xxx");
out << "foo" << endl;
}
//java
OutputStream out = new FileOutputStream("xxx");
out.write("foo\n");
out.close();
可以看到,C++写法里既没有new,也没有close。一对花括号限死了
fstream中所有相关资源的生存期。
而java里,从C++借鉴来一个完全没有必要的new,却没有对应的delete,
而后面的close又没有对应的open。代码没有一点对称性。现在看来,
用来分配内存... 阅读全帖 |
|
N********n 发帖数: 8363 | 41
JAVA GENERICS用TYPE ERASURE做出来的,实现得臭烘烘,谁敢抄那破玩意。C#
GENERICS是借鉴C++ TEMPLATE搞出来的。 |
|
g*****g 发帖数: 34805 | 42 你丫也有脸说,Java Generics的精髓是把C++ template简化并保留了90%的功能,C#全
盘照抄。用不用Type Erasure纯粹是要不要向后兼容。C#这种没人用的东西,当然没有
负担。你要说不是抄Java的,00年C#就出来了,为啥没有Generics。Java 1.5一做,立
马就有了呢? |
|
N********n 发帖数: 8363 | 43
C++ TEMPLATE是98、99年才开始流行起来,C#一开始没有很正常。C++自己的STL也
是过了2000年才定型。JAVA被迫用Type Erasure是因为其最初设计缺陷,所有版本全
挤在一个RUNTIME里面。导致加新FEATURE总要受老版本制约,所以弄个TE出来混。C#
从一开始就强调版本概念,所以没有这个问题。C++老程序多了,也没说为了TEMPATE
就要TE,说到底是JAVA设计烂。 |
|
x***4 发帖数: 1815 | 44 我想implicit parameter 在两个地方:
作为classtag,解决type erasure的问题。这个是jvm的问题,一般用户不细究不会意
识到,而且也不影响理解business logics。
例外就是提供一些arguments,比如说db的session,sort的排序方向之类的。这种我最
怕,因为看别人的code的时侯,常常觉得应该有些参数或者dependency要提供,但是却
到处都找不到。整个code非常难懂。
我其实就是抱怨一下。 |
|
c*****z 发帖数: 1211 | 45 Erasure coding 那是三年前的事了吧…… |
|
w***g 发帖数: 5958 | 46 同意C#是一种很好的语言。而且是C family里最好的。
C#的头Anders是我多年的偶像。此人写pascal编译器出身,
技术吊到不行。C#披着C的外衣,本质上其实是一个更
先进的pascal/delphi。
不过技术好跟吃的开是两回事。C#生于我软,死于我软。
有啥办法。Anders也因为是PC系草根出身,在学术界
没啥影响力。反而倒是Odersky这种混得风声水起的。
java的type-erasure-based generics是一批没有能力的人
作出的极其短视的设计,做起来容易,后患无穷。
C#和java这一点上高下立现。
这个世界就是黄锺毁弃瓦釜雷鸣。
Java |
|
w***g 发帖数: 5958 | 47 同意C#是一种很好的语言。而且是C family里最好的。
C#的头Anders是我多年的偶像。此人写pascal编译器出身,
技术吊到不行。C#披着C的外衣,本质上其实是一个更
先进的pascal/delphi。
不过技术好跟吃的开是两回事。C#生于我软,死于我软。
有啥办法。Anders也因为是PC系草根出身,在学术界
没啥影响力。反而倒是Odersky这种混得风声水起的。
java的type-erasure-based generics是一批没有能力的人
作出的极其短视的设计,做起来容易,后患无穷。
C#和java这一点上高下立现。
这个世界就是黄锺毁弃瓦釜雷鸣。
Java |
|
x***4 发帖数: 1815 | 48 我java,groovy,scala都用过。
java:太啰嗦
groovy:不是很喜欢dynamic type
我现在用scala。主要是写data的lib。还不错,code可以很短,而且type system比较
强大,同一个code可以用在很多地方。不爽的地方:
因为jvm type erasure,某些code要带typetag,classtag,不懂的人会很confused
符号。++, +:, ::, etc。很容易搞错。
不过如果我不是写data的lib的话,我也未必会用scala。 |
|
s******y 发帖数: 28562 | 49 他们的意思是,神经突触的形成和记忆无关?
Reinstatement of long-term memory following erasure of its behavioral and
synaptic expression in Aplysia
Shanping Chen, Diancai Cai, Kaycey Pearce, Philip Y W Sun, Adam C
Roberts, David L GlanzmanCorresponding Author
DOI: http://dx.doi.org/10.7554/eLife.03896Published November 17, 2014 Cite as eLife 2014;10.7554/eLife.03896 Download PDF
Abstract
Long-term memory (LTM) is believed to be stored in the brain as changes in
synaptic connections. Here, we show that LTM storage... 阅读全帖 |
|
s********u 发帖数: 16 | 50 Linux Device Driver Engineer
Organization Description:
Istuary Innovation Group is pioneering a true engine of innovation to
transform ideas into robust tech startups that can scale globally. Istuary
spurs startup success by integrating technological research, venture capital
and business consulting into a unified platform.
As Canada’s largest technology incubation platform, Istuary provides
business and marketing support to commercialize promising innovation.
Istuary’s expanding network in Nort... 阅读全帖 |
|