Uploaded image for project: 'BlueJ'
  1. BlueJ
  2. BLUEJ-558

Codepad inconsistently complains about code

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Lowest
    • Resolution: Done
    • Affects Version/s: 3.1.5
    • Fix Version/s: 3.1.6
    • Component/s: CodePad

      Description

      I entered this code into the codepad:

      java.util.Optional.ofNullable(null).isPresent()
      

      It told me it expected a semi-colon. This gave same error:

      import java.util*;
      Optional.ofNullable(null).isPresent()
      

      This, however, was fine:

      boolean b = Optional.ofNullable(null).isPresent();
      b
      

      I think it's to do with the types. If I cast the null in the first case, it works:

      java.util.Optional.ofNullable((String)null).isPresent()
      

      But I don't immediately see why the assignment should work without error, and yet the expression fails. Is it because we count a type warning in the first case as a reason to fail the compile, but in the assignment it gets ignored because we're confident it's a statement?

        Attachments

          Activity

            People

            • Assignee:
              davmac Davin McCall
              Reporter:
              nccb Neil Brown
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: