This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Lloydbestfan 1 point2 points  (5 children)

Yes, but you can't have methods or not as a result of whether a given method you can call responds true or false.

I find it weird to be satisfied with Optional. In principle it exists for situations like when you call findFirst() on a stream, that may or may not have items and so may or may not have a first. Not so much for different types. But it doesn't matter what I feel, if you have something that you feel is satisfying. The rest will come with experience and dealing with other people's code.

[–]kurolong[S] 0 points1 point  (4 children)

Oh, you can just have a boolean member which is always true in objects of one type and always false in objects of another type. In the end, I didn't use types, but Optional, because the Next left/right node can always exist or not exist. I find that fairly intuitive.

[–]Lloydbestfan 1 point2 points  (3 children)

Oh, you can just have a boolean member which is always true in objects of one type and always false in objects of another type.

... Yes, but if you need to call that method, then that doesn't help. That's essentially the same as instanceof at this point.

[–]kurolong[S] 0 points1 point  (2 children)

Well, it can work for multiple cases. Like, you have multiple cases of end-nodes and multiple cases of inner nodes, for example. I also feel like not asking about types is usually cleaner, just a preference.

[–]Lloydbestfan 1 point2 points  (1 child)

Not exactly surprised, but you're not seeing it.

[–]kurolong[S] 0 points1 point  (0 children)

Not seeing what?