Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

I cant understand what is Order(String orderId){this.orderId=orderId;}

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am learning java as well as. but I found following problems here.



Order(String orderId){this.orderId=orderId;} I cant understanding what is the meaning of this. please help me
 
Saloon Keeper
Posts: 11882
253
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a constructor, but poorly formatted. Have you learned about constructors yet?
 
proeser waikmen
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know some thing about constructor. could you describe me some thing about this?

Thanks.
 
Stephan van Hulst
Saloon Keeper
Posts: 11882
253
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you know some things about constructors, what is it that you don't understand about the indicated line?
 
proeser waikmen
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this.orderId=orderId; this line cant understand
 
Sheriff
Posts: 7051
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is an idiom you will see a lot.  The parameter and the field have the same name, so to differentiate them you use the keyword "this" for the field.  The code is basically saying, "Set the field orderId to the parameter orderId."
 
Bartender
Posts: 2550
120
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

proeser waikmen wrote:this.orderId=orderId; this line cant understand


Have a look at this code:

The above code does the same thing, "this" is implied here.

You can also write it as:

However, "x" is not a good name for a parameter variable, java allows you to use the same name as a local parameter like this:

Java allows you to distinctly identify both variables even though they have the same name. Does this clear things for you ?
 
Nothing up my sleeve ... and ... presto! A tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic