The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
15.8. Primary Expressions
15.8.1. Lexical Literals
15.8.2. Class Literals
15.8.3. this
15.8.4. Qualified this
15.8.5. Parenthesized Expressions
15.9. Class Instance Creation Expressions
15.10. Array Creation and Access Expressions
15.11. Field Access Expressions
15.12. Method Invocation Expressions
15.13. Method Reference Expressions
15.14. Postfix Expressions
15.15. Unary Operators
15.16. Cast Expressions
15.17. Multiplicative Operators
15.18. Additive Operators
15.19. Shift Operators
15.20. Relational Operators
15.21. Equality Operators
15.22. Bitwise and Logical Operators
15.23. Conditional-And Operator &&
15.24. Conditional-Or Operator ||
15.25. Conditional Operator ? :
15.26. Assignment Operators
15.27. Lambda Expressions
15.28. switch Expressions
15.29. Constant Expressions
Mike Simmons wrote:And they don't directly say that it's in order of precedence. They don't talk about precedence directly, at all. But they present in order of precedence, because that's the clearest way to lay out the grammer rules as they have defined them, which implicitly spell out the order of precedence.
15.9. Class Instance Creation Expressions
15.10. Array Creation and Access Expressions
15.11. Field Access Expressions
But there are lots of other language constructs that aren't operators either, and those also have precedence. Those are all spelled out in the details of the JLS.
java: array required, but java.lang.String found
Anil Philip wrote:Thanks. I think it is an assumption that these are in order of precedence - unless they say so.
Precedence among operators is managed by a hierarchy of grammar productions. The lowest precedence operator is the arrow of a lambda expression (->), followed by the assignment operators. Thus, all expressions are syntactically included in the LambdaExpression and AssignmentExpression nonterminals:
Expression:
LambdaExpression
AssignmentExpression
Anil Philip wrote:I don't know why they wouldn't make a table.
Mike Simmons wrote:Well, Strings aren't arrays. There's no problem with precedence there, but Java does not support treating a String as an array. Other languages do, because it's a concise way to access an individual character, but Java does not.
Tim Holloway wrote:The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
I saw the quote before. I agree but I didn't understand the last bit. What is it saying about the "willfully-blind idiot"? What are they guaranteed?
Mike Simmons wrote:SvH++
Neither of us can tell what you want to do here, and neither can the compiler.
Also, it's "Buonaserata", since "serata" is feminine.
Anil Philip wrote:I want to create an array of String using
as the constructor, not an array containing nulls.
It is also incorrect in not mentioning the left‑to‑right rule.Mike Simmons wrote:Unfortunately, that Princeton table is incorrect. . . .
Anil Philip wrote:I want to create an array of String using
as the constructor, not an array containing nulls.
Won't that make var mean Object[]? Don't you prefer to add String[]::new somewhere?Stephan van Hulst wrote:. . .
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Tim Holloway wrote:Technically, there's no reason why you cannot make the "[]" operator set equivalent to charAt(), and if enough people pushed for it, it might even be so, some day.
Tim Holloway wrote:But there are some caveats. First, in its current internal incarnation, you cannot always determine charAt(x) via simple byte offset, since String now allows some variable-length character constructs in the interests of storage efficiency.
Tim Holloway wrote:More importantly, though, String is immutable. In a normal Java array, a "x[y]" is a legitimate lefthand-side (LHS) expression token in all cases. And since String is a subclass of class Object, you couldn't always detect mis-use at compile time.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
That would be inconsistent with the current state of the JLS. It would make it into a different language. I think that section is there to warn people that Java®≠C++. I don't know much C++, but I know, in C, there is no such thing as a String, only a char[], maybe more precisely, a char*.Tim Holloway wrote:A note regarding treating Strings like character arrays.. . .
Nor am I"An idiot is never wrong".
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Tim Holloway wrote:
I don't think the compiler could catch this. It would need a runtime Exception.
Is that what I was supposed to notice?Tim Holloway wrote:. . . It would need a runtime Exception.
Tim Holloway wrote:Every new version of Java changes the state of the JLS. That's what makes it a new version.
java.lang.String.codePoints wrote:codePoints
public IntStream codePoints()
Returns a stream of code point values from this sequence. Any surrogate pairs encountered in the sequence are combined as if by Character.toCodePoint and the result is passed to the stream. Any other code units, including ordinary BMP characters, unpaired surrogates, and undefined code units, are zero-extended to int values which are then passed to the stream.
Specified by:
codePoints in interface CharSequence
Returns:
an IntStream of Unicode code points from this sequence
Since:
9
Mike Simmons wrote:My point in bringing up code points was not to know how we handle them - there are a number of methods for this. But for this hypothetical "str[i]" notation, it's not clear whether it should refer to chars or code points, since they are different things.
Code points hadn't been invented back then. I think it is Cay Horstmann who said that code points took Java® by surprise, even though Strings were designed to use Unicode from day one.Mike Simmons wrote:. . . They weren't even thinking about code points when they originally designed it. . . .
Stephan van Hulst wrote:
Unicode 2.0 replaced UCS-2 with UTF-16. UTF-16 is backwards compatible with UCS-2, but it encodes a superset of the character set encoded by UCS-2, which also meant that a 2 byte char could no longer represent all code points.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Tim Holloway wrote:However, as mentioned previously, a String is not intended to be literally a set of code points, but rather a sequence of Characters.
How many bytes a given code point requires (especially if compaction algorithms are applied) is not germane to the issue.
It's a mistake to think that "char" == "byte".
Don't get me started about those stupid light bulbs. |