Ah yes, Stack not Number, that was just me checking whether a false case
was detected and I forgot to change it back.

On Sat, Jun 6, 2020 at 3:24 PM Jochen Theodorou <blackd...@gmx.org> wrote:

> On 06.06.20 06:57, Paul King wrote:
> > Here is a good example for your point Jochen:
> >
> > ///////////////////
> > @groovy.transform.TypeChecked
> > def method() {
> >      def component = new Random().nextBoolean() ? new ArrayDeque() : new
> Stack()
> >      component.clear() // 'clear' in LUB (AbstractCollection or
> Serializable or Cloneable)
> >      if (component instanceof ArrayDeque) {
> >          component.addFirst(1) // 'addFirst' only in ArrayDeque
> >      } else if (component instanceof Stack) {
> >          component.addElement(2) // 'addElement' only in Stack
> >      }
> >      if (component instanceof ArrayDeque || component instanceof Number)
> {
> >          // checked duck typing
> >          assert component.peek() in 1..2 // 'peek' in ArrayDeque and
> Stack but not LUB
> >      }
> > }
> >
> > method()
> > ///////////////////
>
> I guess
>
> if (component instanceof ArrayDeque || component instanceof Number) {
>
> is really
>
> if (component instanceof ArrayDeque || component instanceof Stack) {
>
> > The peek() case is what you call LUBU. I am still not sure what the best
> > name is.
> > This is where we'd need either an invokedynamic or smarter multi-branch
> > logic with several alternative invokevirtual paths.
>
> I would go with invokedynamic. That is better for debugging and code
> coverage tools.
>
> bye Jochen
>
>

Reply via email to