0

Like this:

Kernel kernel = new Kernel() {};

I can't figure out the name of it. I'd like to know what this is called so I can learn more about it, but unfortunately I haven't been able to find the answer myself through search engines.

k_ssb
  • 6,024
  • 23
  • 47
dan dan
  • 475
  • 1
  • 3
  • 12
  • 3
    Anonymous class. – markspace May 28 '18 at 00:17
  • 1
    @dandan Don't feel bad that you asked a duplicate -- it's sometimes hard to know the correct search terms as you mentioned. We mark questions as duplicate to improve the site's organization (pointing readers of your question to other relevant information), not to "punish" you or put you down in any way. – k_ssb May 28 '18 at 00:32
  • yeah thanks i was talking about downvotes though – dan dan May 28 '18 at 00:33
  • @dandan Don't worry too much about them. I think your question was fine (it's clear what you're asking, and you couldn't have improved it without knowing the answer). At least up-/down-votes have equalized now :) – k_ssb May 28 '18 at 00:37

1 Answers1

2

It's called an anonymous class. Excerpt from the Oracle tutorial:

The anonymous class expression consists of the following:

  • The new operator

  • The name of an interface to implement or a class to extend. In this example, the anonymous class is implementing the interface HelloWorld.

  • Parentheses that contain the arguments to a constructor, just like a normal class instance creation expression. Note: When you implement an interface, there is no constructor, so you use an empty pair of parentheses, as in this example.

  • A body, which is a class declaration body. More specifically, in the body, method declarations are allowed but statements are not.

k_ssb
  • 6,024
  • 23
  • 47