课程: Java Object-Oriented Programming
今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
Accessing specific object forms with instanceof - Java教程
课程: 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…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
-
-
(已锁定)
What is polymorphism?1 分钟 22 秒
-
(已锁定)
Writing reusable algorithms with runtime polymorphism4 分钟 47 秒
-
(已锁定)
Exploring different forms in a single object4 分钟 6 秒
-
(已锁定)
Accessing specific object forms with instanceof4 分钟 23 秒
-
(已锁定)
Writing flexible code with compile-time polymorphism4 分钟 38 秒
-
(已锁定)
Exploring how built-in Java classes use polymorphism3 分钟 39 秒
-
(已锁定)
Challenge: Reduce complexity with polymorphism48 秒
-
(已锁定)
Solution: Reduce complexity with polymorphism6 分钟 57 秒
-
(已锁定)
-
-