From the course: Java Object-Oriented Programming
Unlock the full course today
Join today to access over 23,200 courses taught by industry experts.
Accessing specific object forms with instanceof - Java Tutorial
From the course: Java Object-Oriented Programming
Accessing specific object forms with instanceof
- [Instructor] With the OddArrayList class, we created a very specific condition. An item is added depending on whether it's odd or not. We can broaden this class by making it a condition ArrayList where items are added based on a given condition. Let's rename this class to ConditionArrayList. We'll left click on the name, hover over Refactor and rename the references. This is a feature of IntelliJ. Now, since items will be added based on a condition, we'll need to include that condition in the constructor. This condition will be a predicate, something that takes in a value and returns true or false. The predicate could be whether or not the number is positive, whether it's divisible by three or whatever we want. It's defined on creation and that's what we filter our list on. Now, since we'll want to access this predicate in a variety of instance methods, we should make this predicate an instance variable and then we…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
What is polymorphism?1m 22s
-
(Locked)
Writing reusable algorithms with runtime polymorphism4m 47s
-
(Locked)
Exploring different forms in a single object4m 6s
-
(Locked)
Accessing specific object forms with instanceof4m 23s
-
(Locked)
Writing flexible code with compile-time polymorphism4m 38s
-
(Locked)
Exploring how built-in Java classes use polymorphism3m 39s
-
(Locked)
Challenge: Reduce complexity with polymorphism48s
-
(Locked)
Solution: Reduce complexity with polymorphism6m 57s
-
(Locked)
-
-