Problem with default methods in an interface?

edited April 2015 in Questions about Code

It's possible (as far as I can tell, likely) that this is a bug with Processing's compiler, but I figured I'd check here before I make a bug report.

Here is the code in question (reproduced in the most general case):

` interface TestInterface { default void doSomething() {

} } `

attempting to compile this produces the error message "Found one too many { characters without a } to match it".

  1. Is there any error with the syntax or semantics of this code? Perhaps I'm forgetting something?
  2. Do you experience this error?

Putting the following code: ` package testy;

public class Test {

public static void main(String[] args) {
    // TODO Auto-generated method stub

}

public interface TestInterface
{
    default int returnFour()
    {
        return 4;
    }
}

} `

in Eclipse has yielded no compile issues, so I suspect this may be a bug. I am using Processing 2.2.1, please include your version number with your answer.

(Disclaimer: I did try to use the "code" block denoted by `, but couldn't get it to work at all, at least in the preview. If some kindly mod understands why this dark magic is not working and knows how to fix it, please go ahead)

Answers

  • edited April 2015 Answer ✓
    • The PDE (Processing's IDE) got a pre-processor which transpiles some Processing's syntax sugar into Java valid code.
    • Unfortunately It's not even fully Java 5 compliant, much less Java 8 or 9!
    • And Processing's devs aren't very interested in fixing the pre-processor!
    • For example: We can't use package nor enum!
    • Only solution is placing incompatible code into a ".java" instead of a ".pde" file.
    • Processing's pre-processor won't touch ".java" files.
  • I hadn't even remembered where I first read about default methods, and so forgot that they were a Java 8 thing. Thanks!

  • See How to format code and text

    The backticks should be used only for fragments of code, not for several lines. Apparently, lot of new users click on the C button then paste the code. That's not how it must be done. You have to paste the code, select it then hit the C button. It should indent the code.

Sign In or Register to comment.