Skip to main content

Questions tagged [java]

For questions about Java's design, or languages which are closely related to Java

3 votes
1 answer
1k views

Strings and arrays in Project Valhalla

My understanding of Project Valhalla's impact on arrays and Strings (please let me know if this is off): arrays will still be reference objects but an array of ...
BPS's user avatar
  • 133
5 votes
2 answers
645 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 ...
terrorrussia-keeps-killing's user avatar
2 votes
5 answers
1k 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 ...
CPlus's user avatar
  • 10.5k
21 votes
3 answers
3k views

How do lexers/parsers distinguish between nested generics and bitshifts?

The lexical grammar of Java has a special case for the > character. Normally, tokens are formed based on the longest-match rule, so that an input string of ...
kaya3's user avatar
  • 22.4k
10 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. ...
Michael Homer's user avatar
  • 15.3k
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 ...
FireTheLost's user avatar
  • 1,651
6 votes
3 answers
958 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 ...
CPlus's user avatar
  • 10.5k
8 votes
1 answer
209 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 ...
MI3Guy's user avatar
  • 221
7 votes
1 answer
231 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 ...
Ginger's user avatar
  • 2,707
13 votes
5 answers
561 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,...
ice1000's user avatar
  • 2,748