And that is a relatively new construct, being introduced in Java7.
Carey Brown wrote:. . . . Off hand, I can only think of one place where Java does that. . . .
Tim Holloway wrote:But when I typed "long max = 312356789;" into Eclipse it worked just fine without the "L" qualifier.
Afraid that won't compile, nor will it compile if you take the () off and apply the cast to 31235678922, because you are overflowing the range of an int. The only way you can get that to compile is to append an L to the number literal (case‑insensitive, but never use lower‑case). More details in the Java® Language Specification (=JLS). It doesn't matter which order you compile the different tokens; you will eventually encounter the token “31235678922”, which is outwith the syntactic rules in that JLS section. This is what you find if you scroll down about two pages:-
Tim Holloway wrote:. . . long max = (long) (31235678922 / 2200);
Remember that the range of octal, binary, and hexadecimal int literals is twice as large as for decimal literals.
That JLS section wrote:It is a compile-time error if the decimal literal 2147483648 appears anywhere other than as the operand of the unary minus operator; or if a decimal literal of type int is larger than 2147483648 (2³¹).
Who? Probably Brian Kernighan and Dennis Ritchie; I think the same conventions applied in C, but maybe they are even older than C. I think Gosling tried to keep Java® syntax looking as similar to C/C++ as possible, so we are given the L.
Matt Wong wrote:. . . someone in the past decided so . . .
you can't change it anyway . . .
Matt Wong wrote:i know that some of the mods maybe not so cool with this reply, but most topics wich title is "why is X the way it is and not Y?" and repeat that question in the post can be answered with: "because someone decided so" or "cause it has to / can't be Y"
Surely that's the reason for agreeing to the interview
Tim Holloway wrote:. . . answer ranges from . . . to "I think I was drunk." . . .
I believe he was also influenced by a language called BCPL, but I know absolutely nothing about it.
when Dennis Ritchie designed C, he took a little bit of Fortran, a little bit of Algol, perhaps a smidgen of a few other languages, . . .
. . . and that 4kB cost about the same as buying a whole street round here; nowadays I can buy 1,000,000× that memory for the price of dinner with the Missus.
had to run as multiple overlays in a 4 Kilobyte memory space, . . .
But you find that the stricter the language, the more errors are caught early and the fewer errors escape into the big wide world.
Java . . . was designed fairly strictly. . . . .
Campbell Ritchie wrote:I believe he was also influenced by a language called BCPL, but I know absolutely nothing about it.
Campbell Ritchie wrote:But you find that the stricter the language, the more errors are caught early and the fewer errors escape into the big wide world.
Tim Holloway wrote:. . . British Cruddy Programming Language. . . . .
My first bit of advice is that if you are going to be a mime, you shouldn't talk. Even the tiny ad is nodding:
global solutions you can do in your home or backyardhttps://coderanch.com/t/708587/global-solutions-home-backyard