From the course: Java 8+ Essential Training: Objects and APIs

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Organize code with nested types

Organize code with nested types - Java Tutorial

From the course: Java 8+ Essential Training: Objects and APIs

Start my 1-month free trial

Organize code with nested types

- So far whenever I've wanted to create a new class or other type in my application, I've defined it in its own file. But you can combine types together in a parent/child relationship within a single file. These are then called nested types, or sometimes member types. Let's take the operation enum that I created in a previous video. Right now it's in its own file, operation.java. But it's obviously clearly related to the MathHelper class. It's only used when you're either calling the MathHelper class or within the MathHelper class' code. So this is an opportunity to reorganize the code and make things a little bit easier to find. I'll start in operation.java, and I'll copy the enum declaration to the clipboard. Then I'll go back to MathHelper.java, I'll place the cursor within the class declaration, but outside of any methods, and I'll paste that code into place. Now operation is a nested enum. It's a nested type of the MathHelper class. I'll come back to operation.java, and I'm going…

Contents