392 questions
8
votes
1
answer
253
views
Is it allowed to select a static class from a parameterized type in Java?
Here's a minimal demo:
public class OuterStaticNestedDemo<E> {
class Outer {
static class StaticNested {}
}
void qualifiedNew(Outer outer) {
new Outer.StaticNested();...
5
votes
0
answers
85
views
Why does directSupertypes() not return a raw type as required by JLS 4.10?
The contract for Types#directSupertypes(TypeMirror) says that it will return "the direct supertypes of a type". It also references section 4.10 of the Java Language Specification.
The set of ...
4
votes
1
answer
225
views
Does Java permit unbounded starvation?
Introduction
Consider this Java program:
public class Loop {
static volatile boolean flag;
public static void main(String[] args) {
new Thread(() -> flag = true).start();
...
1
vote
2
answers
139
views
Why does the Java Memory Model allow reads to observe future writes?
There seems to be a similar question (Java Specification: reads see writes that occur later in the execution order), but it focuses on a different example.
The Java Memory Model states in §17.4.8:
...
3
votes
1
answer
147
views
Can r1 == 0 and r2 == 0 occur without volatile in this Java program?
Do I understand correctly that if I run run1() and run2() in parallel, the result r1 == 0 and r2 == 0 is impossible under any circumstances, even though a and b are not volatile?
public class Example {...
0
votes
0
answers
70
views
Is a Noop JVM valid under the Java Memory Model?
I'm trying to understand the Memory Model chapter from the Java Language Specification, but I'm already confused by the first two paragraphs:
A memory model describes, given a program and an ...
2
votes
0
answers
58
views
A counter example for narrowing reference conversion rules in Java [duplicate]
Consider the rules of allowed narrowing reference conversion mentioned in the JLS section 1.5.6.1.
The following is an example of a narrowing reference conversion:
ArrayList<? extends Integer> l ...
2
votes
1
answer
56
views
Anonymous classes can refer to inaccessible type in the signature of the supertypes?
Consider the following clause from JLS 8: § 15.9.5.1. Anonymous Constructors
Note that it is possible for the signature of the anonymous constructor to refer to an inaccessible type (for example, if ...
1
vote
0
answers
188
views
Why is the following method reference illegal?
I have some confusion about how method references work.
The following is an example from JLS 15.13.1:
An example of ambiguity is:
interface Fun<T,R> { R apply(T arg); }
class C {
int ...
3
votes
0
answers
75
views
Which part of the Java Language Specification specifies the behavior of this conversion?
I was working on a project that parses Java code. While testing my project on some code I found out that it throws an error on cases like the one under, specifically on the conversion of type B<A&...
0
votes
1
answer
90
views
Type arguments of inner generic classes in Java
JLS 4.5.2:
If any of the type arguments in the parameterization of C are
wildcards, then:
• The types of the fields, methods, and constructors in C<T1,...,Tn>
are the types of the fields, ...
-1
votes
1
answer
81
views
How should I determine the members of the following intersection types?
interface A{
}
interface B{
}
interface C{
}
interface D extends A,B,C{
}
If there is:
class N<T extends A & B & C>
According to the content of JLS 4.9:
Every intersection type T1 ...
1
vote
2
answers
184
views
What are the values of an intersection type in Java?
I don't understand this passage in the Java Language Specification :
JLS § 4.9:
The values of an intersection type are those objects that are values
of all of the types Ti for 1 ≤ i ≤ n.
As far as I ...
2
votes
2
answers
252
views
Class inherits two override-equivalent methods
Consider this rule from the Java Language Specification 21th edition:
It is a compile-time error if a class C inherits a default method whose signature is override-equivalent with another method ...
0
votes
1
answer
89
views
What situation is explained by the following statement in the Java language specification?
JLS 4.8:
It is a compile-time error to pass type arguments to a non-static
member class or interface of a raw type that is not inherited from its
superclasses or superinterfaces.
I can't think of ...