Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why Avoid Optional Semantics?

avoid semantics
0
Posted

Why Avoid Optional Semantics?

0

• A type should mean: “what an object can do for me.” • Here’s a different approach: package java.util; public interface Iterator { // Returns true if the iteration has more elements. boolean hasNext(); // Returns the next element of the iteration. Object next(); } package java.util; public interface Removerator extends Iterator { // Removes from the underlying collection the last // element removed by the iterator void remove(); } • Here, Removerator means an Iterator that can remove elements from the underlying collection • Optional code is likely slower than types code, because throwing exceptions is slow • Optional code robs you of strong typing at compile time that can help you catch errors sooner.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123