Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Method arguments in Java must be expressions. An operator by itself is not an expression. This is not possible in Java.</p> <p>You can, of course, pass objects (maybe <code>enum</code> constants) that represents those operators, and act accordingly, but you can't pass the operators themselves as parameters.</p> <hr> <h3>Additional tips</h3> <p>Since you're just starting Java, it's best to ingrain these informations early on to ease your future development. </p> <ul> <li>Method names starts with lowercase: <code>calculate</code> instead of <code>Calculate</code></li> <li>Variable names starts with lowercase: <code>operator</code> instead of <code>Operator</code></li> <li><code>Double</code> is a reference type, the box for primitive type <code>double</code>. <ul> <li><em>Effective Java 2nd Edition, Item 49: Prefer primitive types to boxed primitives</em></li> </ul></li> <li>Don't <code>return "error..."</code>. Instead, <code>throw new IllegalArgumentException("Invalid operator");</code></li> </ul> <h3>See also</h3> <ul> <li><a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/autoboxing.html" rel="nofollow noreferrer">Java Language Guide/Autoboxing</a></li> <li><a href="http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html" rel="nofollow noreferrer">Java Lessons/Exceptions</a></li> <li><a href="http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html" rel="nofollow noreferrer">Coding Conventions/Naming</a> <ul> <li>Unfortunate typo in this document: <a href="https://stackoverflow.com/questions/2711186/how-is-this-statement-making-sense-suns-naming-convention-for-java-variables">How is this statement making sense? (Sun’s naming convention for Java variables)</a></li> </ul></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload