From: Alexander S. <ast...@ma...> - 2007-01-22 15:42:41
|
On Jan 20, 2007, at 5:25 AM, Diez B. Roggisch wrote: >> 2) Jython (non)interaction with java generics >> Jython completely ignores java generics. In my opinion this is >> trivial but non-obvious. It is trivial once I remember that java >> generics have no support in the JVM and are essentially compile >> time magic (please correct me if i am wrong on this). It is non- >> obvious because I don't normally think about such things when >> just using code. I wouldn't have seen this behavior without >> deliberately setting out to test it. >> Generics provide no type safety to jython scripting on java >> collections. I suspect this could be the source of nasty bugs for >> the unwary. Is this issue worthy of documenting? > > Why do you single out generics? There is no type annotation support > in jython _anywhere_, it is the very reason I prefer jython over > java in most cases. > > So why should anybody expect > > foo = "bar" > foo = 100 > > to work, while > > map.put("foo", 100) > map.put(100, "foo") > > expect to puke with type errors? I was thinking specifically of the case of interacting with existing java libraries. Java methods still demand correct typing when used from jython. You get errors when doing things like: >>> d = java.util.Date("'100") And the same would be true for methods on any java classes one has written. However misusing a java generic will give no such error. So you may get a deferred type error in java code which a java programmer would think has been prevented by specifying the generic. So the issue isn't the lack of type safety in jython, which I agree is generally a gain, but the "odd" behavior of generic typing in java code called from jython. Without thinking carefully about it one might start looking for bugs in the wrong places. Alex |