From the course: Java Object-Oriented Programming

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Writing flexible code with compile-time polymorphism

Writing flexible code with compile-time polymorphism - Java Tutorial

From the course: Java Object-Oriented Programming

Writing flexible code with compile-time polymorphism

- [Instructor] Java also supports compile-time polymorphism to make your code faster and cleaner. With compile-time polymorphism we can have more than one method with the same name, let's take a look. With the ConditionArrayList, we can create a new list with a predicate. In this case, the condition is if the number isDivisibleByThree. We can also create a ConditionArrayList by providing a series of numbers, in addition to the predicate. Only those that satisfy the condition will be added to the list. We're able to use the constructor in this way, because the second input to our constructor is a variable argument. You can input zero numbers, one number, or as many as you want. However, they do have to be in a series or array format. If you want to add another list or collection to the ConditionArrayList, it's currently not possible. In fact, when we try we get an error saying it cannot resolve the constructor, and…

Contents