Scala syntax bug? -


i have encountered think bug/no-syntax-sense in scala syntax prefer post here after reporting might wrong.

the controller class:

package  import java.awt.event.actionlistener import java.awt.event.actionevent  class itemcontroller extends actionlistener {    val new_item = "new item"   val update_item = "update item"    private val newitem = new itemnew    override def actionperformed(e: actionevent) = {    }    def create(view: string) = {      view match {       case new_item => {         newitem eraseform //here eclipse says "unit not take parameters".         newitem setvisible true       }        case update_item =>     }    }  } 

the view class

  package    import scala.collection.mutable.hashmap   import javax.swing.jpanel   import java.awt.gridlayout   import javax.swing.jframe   import scala.collection.mutable.linkedhashmap   import javax.swing.jtextfield   import java.awt.borderlayout   import java.awt.flowlayout   import javax.swing.jlabel    class itemnew extends jframe {      private val formfields = linkedhashmap[string, jtextfield]()      init      private def init(): unit = {       // defining form fields       formfields += ("name" -> new jtextfield(20),         "surname" -> new jtextfield(20),         "age" -> new jtextfield(3))        setlayout(new borderlayout)        val formpanel = new jpanel       formpanel setlayout (new gridlayout(formfields.size, 1))        generateform(formpanel)       getcontentpane add formpanel        pack       setvisible(true)        def generateform(formpanel: jpanel) = {          var leftpanel: jpanel = null         var rightpanel: jpanel = null         var gridpanel: jpanel = null          formfields foreach (entry => {            leftpanel = new jpanel(new flowlayout)           leftpanel.getlayout().asinstanceof[flowlayout] setalignment flowlayout.left            rightpanel = new jpanel(new flowlayout)           rightpanel.getlayout.asinstanceof[flowlayout] setalignment flowlayout.left            gridpanel = new jpanel(new gridlayout(1, 2))            leftpanel add new jlabel(entry._1 + ':')           rightpanel add entry._2            gridpanel add leftpanel           gridpanel add rightpanel            formpanel add gridpanel          })       }     }      def getformcontent: hashmap[string, string] = {        val formdata = hashmap[string, string]()        formfields foreach (entry => {         formdata += (entry._1 -> entry._2.gettext)       })        return formdata     }      def eraseform : unit = {       formfields foreach (entry => {         entry._2 settext ""       })     }      private def addlisteners = {      }    } 

see comment in itemcontroller class. if leave blank line between statement comment , newitem setvisible true code gives no error.

thanks in advance.

newitem eraseform newitem setvisible true 

is parsed as

newitem.eraseform( newitem).setvisible(true); 

but want have is:

newitem.eraseform; newitem.setvisible(true); 

leaving out dots , parentheses means scala compiler applies "operator notation". means expression needs of form obj meth param. possible have obj meth; can see form needs stopped semicolon. can either insert or let compiler infer adding empty line, expression starts keyword in following line or closing braces , parentheses.

since 2.10 warning if write obj meth because such postfix operators can harmful can see question.

see these 2 question , answers more information on "operator notation" rule:


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -