Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 8 Interface clinit invocation #9090

Closed
dankurka opened this issue Jun 10, 2015 · 3 comments
Closed

Java 8 Interface clinit invocation #9090

dankurka opened this issue Jun 10, 2015 · 3 comments
Assignees
Milestone

Comments

@dankurka
Copy link
Member

Originally reported on Google Code with ID 9156

In Java 7 when you instantiate an instance of type Foo that extends type Bar, the clinit
for Bar is run and then the clinit for Foo is run. If Foo extends interface Baz which
contains some static fields, the clinit for Baz is NOT run when Bar is instantiated.

But this stays mostly the same in Java 8 except when interface Baz contains a default
method. In this situation the clinit for Baz IS run when Bar is instantiated, *even
if the default method is unreferenced*.

Reported by stalcup@google.com on 2015-03-20 22:28:56

@dankurka
Copy link
Member Author

Reported by stalcup@google.com on 2015-03-20 22:29:09

  • Labels added: Category-Compiler

@dankurka
Copy link
Member Author

JLS section 12.4.1 (https://docs.oracle.com/javase/specs/jls/se8/html/jls-12.html) describes
initialization semantics.

Difference between Java8 and 7:
  - When a class is initialized in 8 all superinterfaces that declare any default methods
should be initialized (12.4.2. step 7 describes the order in which superinterfaces
are to be initialized)
  - when a static interface method is called the interface is initialized

Java 8 gives the compiler some leeway: " Note that a compiler may generate synthetic
default methods in an interface, that is, default methods that are neither explicitly
nor implicitly declared (§13.1). Such methods will trigger the interface's initialization
despite the source code giving no indication that the interface should be initialized."


So if the compiler synthesizes default method, then those interfaces are initialized
as per previous description.



Reported by rluble@google.com on 2015-03-24 16:50:08

@rluble rluble assigned rluble and unassigned dankurka Nov 10, 2015
@rluble
Copy link
Contributor

rluble commented Nov 10, 2015

Review pending at: https://gwt-review.googlesource.com/#/c/13951/

hubot pushed a commit that referenced this issue Nov 11, 2015
Change-Id: Ibdc432f0ea7acb894a0616a3764ec7e65b297b5d
Bug-Link: #9090
@tbroyer tbroyer modified the milestone: 2.8 Apr 14, 2016
@tbroyer tbroyer closed this as completed Apr 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants