java - Differents between datatypes and Unit -


when cases in programming java or scala got error

type mismatch; found : unit required: string  

that because of domain or entity g/set methods got error.

why got error? and

how can overcome error?

for example show entity , error codes in scala programming

domain

//@beanproperty line commented  @column(name="username") var username:string=null  def getusername() {    this.username = username  }  //@beanproperty @column(name="password") var password:string=null def getpassword() {    this.password = password  } def setpassword(password:string) {    this.password = password  } 

and error got here

@transactional(propagation = propagation.required )   def loaduserbyusername(username: string): userdetails = {     log.info("==>calling loaduserbyusername user " + username);     val useraccount: useraccount = finduseraccount(username);     new user(useraccount.getusername(), useraccount.getpassword(),      here error    ---^                       ^---- , here       true, true, true, true, getgrantedauthorities(useraccount));   } 

the compilation error shows :

multiple markers @ line     - type mismatch; found : unit       required: string 

if know these please share her..

with regards milano :)

as thilo mentioned, getters setters. if want return e.g. username have write this:

def getusername():string = {     this.username } 

important = sign, means, function return (in case username ). :string defines return type. without = void method in java, user object expects string here, while getusername() function without return type (= unit):

new user(useraccount.getusername(), useraccount.getpassword()) 

Comments