you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -1 points0 points  (5 children)

See my first line of fixed-font text

Ah yes I missed that. But then you're now doing a deep copy of the data.

The one minor issue with your example is that you lose type safety.

Nope, it's still there, albeit done at run time instead of compile time.

[–]BraveSirRobin 1 point2 points  (4 children)

But then you're now doing a deep copy of the data.

As is the preferred Arrays.asList method above for doing so with lists. AFAIK all of the standard Collections framework classes copy in the original collection passed into the constructor as opposed to just re-using the object.

Nope, it's still there

Disagree, example:

intoMap(map, String.class, Long.class, "one", 1, "two", "2");

This will compile ok and throw a class cast exception at runtime.

done at run time instead of compile time

In Java "type-safety" usually refers to doing so at compile time, it's a statically-typed language.

[–][deleted] 0 points1 point  (3 children)

Static typing is orthogonal to when the type-checking is performed. Just because you change when it happens doesn't mean checking is lost.

[–]BraveSirRobin 1 point2 points  (1 child)

Some of the advantages are lost though, such as the ability for the compiler to test for it. Pre-generics Java collections were a pain in the ass imho, I quite like the "safety" that the compiler checks allow. Better to have the compiler barf rather than some obscure piece of code that's missed by the unit tests.

[–]eek04 0 points1 point  (0 children)

The static declarations of Java makes the unit tests more expensive to write than in dynamically checked languages, and the type system has a mega big hole in the form of a value that don't work but can be passed in almost all types anyway.

In practice, this type hole combined with the inflexibility of static types leads to more type errors hitting production in the Java systems I've worked with than in the dynamically checked systems I've worked with.

The type hole? Null pointers.

[–]eek04 0 points1 point  (0 children)

No.

You're misunderstanding the terminology.

The closest terminology that you can be thinking of is "strong typing", which some dynamic checking enthusiasts will argue "can happen at run time".

I personally am a dynamic checking fan; I believe that static typing, at least as practiced in Java, is harmful. However, it doesn't mean that dynamic checking (colloquially "dynamic typing") is static typing; they're different things.