Questions tagged [java]
For questions about Java's design, or languages which are closely related to Java
9
questions
2
votes
1
answer
303
views
What if all static methods in Java or C# could be extension methods just by default?
C# 3.0 introduced extension methods to "enhance" behavior of existing types without interface bloating to avoid modifying/breaking existing interfaces. This was the first time I learned of ...
1
vote
3
answers
334
views
Is there any way a Java-like language could implement immutable primitive arrays without incurring performance penalties?
I asked: What prevents Java from having immutable primitive arrays? a while back and got an answer: Because immutable primitive arrays would typically require checking some immutable flag every time a ...
17
votes
2
answers
3k
views
How do lexers/parsers distinguish between nested generics and bitshifts?
The lexical grammar of Java has a special case for the the > character. Normally, tokens are formed based on the longest-match rule, so that an input string of <...
9
votes
1
answer
2k
views
Why can you implement a Monoid type in Java or C#, but not Monad or Functor?
Haskell and some other functional languages have Monad and Monoid types (and Semigroup, Functor, Applicative, and many others), and lists, trees, Maybe, and other types subtype all or some of these. ...
15
votes
4
answers
4k
views
When would a Java style enum be better than a C++ style enum, and vice versa?
In Java, enum values behave like objects (since they are basically syntactic sugar for objects) and they can have their own class methods. In C++, however, enums are essentially an alias for an ...
6
votes
3
answers
828
views
Why might a language avoid reallocation?
In Java, the size of arrays are immutable. However, to my understanding, they are still allocated on the heap, because Java allocates almost everything on the heap. Even then, Java arrays are still ...
8
votes
1
answer
118
views
How can it be determined that a cast or type test is unchecked?
In languages like Java that use type erasure for generics, some casts are considered unchecked. One example is casting a value of Object to ...
7
votes
1
answer
178
views
What are the advantages and disadvantages of package declarations?
Java-family languages often use a package declaration at the top of a source file, to group source files into modules/packages independently of their file system ...
12
votes
5
answers
415
views
What are the advantages of having first-class functions versus having only anonymous class with fancy sugars?
In Java, there are "SAM-interfaces" which are used as "types" for lambda expressions. In Haskell, there are dedicated types for functions. In Rust, there are no types for functions,...