Skip to content
This repository was archived by the owner on Sep 8, 2021. It is now read-only.
This repository was archived by the owner on Sep 8, 2021. It is now read-only.

Why not allow multiple static blocks? #26

@bakkot

Description

@bakkot

In Java a class can have multiple static {} blocks, which is useful (among other occasions) when you have multiple fields you want to initialize: it lets you write

class Foo {
  static Map<Object, String> names = new HashMap<>();
  static {
    // initialize names
  }

  static Map<Object, Integer> ids = new HashMap<>();
  static {
    // initialize ids
  }
}

What's the motivation to disallow this?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions