Skip to content

Elvis ?: [enhacement] #28

Description

@pablogrisafi1975

Thanks again for your extraordinary work.
You said that adding new operator is difficult because of no extension points at that stage. What about the elvis ?: operator, better known as null coalescing operator ? you know, instead of

String firstName = user == null ? null : user.getFirstName()

i'd like to write

String firstName = user?:getFirstName()

I don't know if that counts as a new operator, since both chars already have a meaning

Activity

  1. almson commented on Jul 13, 2015

    @almson

    It doesn't parse, so I'm guessing it cannot be done. But how about a lady gaga operator ?$:?

  2. pablogrisafi1975 commented on Jul 13, 2015

    @pablogrisafi1975
    Author

    is that possible? At first I thought it was a joke, but then I saw it as

    String firstName = user ? $ : getFirstName() 
    

    And I assume somehow $ is a magical variable that doesn't mess with the type system.

    Mi ignorance about the whole source file -> class file process is almost perfect, so I don't know what can be done in each stage.

    If it is possible, it is a nice workaround, and while somehow strange, it is way better than

    String firstName = user == null ? null : user.getFirstName() 
    
  3. almson commented on Jul 13, 2015

    @almson

    Yes, it should be possible if the $ variable is defined in the background
    (the way lombok defines 'val'). However, your last example is the null-safe
    dereference operator, which is different from elvis, and is usually ?..
    Anyway, I don't know much about the limits of compiler plugins either.

    On Mon, Jul 13, 2015, 8:44 AM Pablo Grisafi notifications@github.com
    wrote:

    is that possible? At first I thought it was a joke, but then I saw it as

    String firstName = user ? $ : getFirstName()

    And I assume somehow $ is a magical variable that doesn't mess with the
    type system.

    Mi ignorance about the whole source file -> class file process is almost
    perfect, so I don't know what can be done in each stage.

    If it is possible, it is a nice workaround, and while somehow strange, it
    is way better than

    String firstName = user == null ? null : user.getFirstName()

    —
    Reply to this email directly or view it on GitHub
    #28 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions