• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Difference between

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




Thanks for help in advance.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Anu, and welcome to the Ranch!

In the future, please UseAMeaningfulSubjectLine(⇐click).

As for your question, you can see for yourself what the difference is. In the first case, you have two MyRunnable objects and in the second case you only have one.
 
Greenhorn
Posts: 27
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, the first one declares two anonymous objects, while the second utilizes one that is referenced by a pointer variable, 'r'.
Use the first method if you're not going to be using those objects again. Use the second method if you are.

Example code (reading in an image):

Note that, because I only need to create a File object for the sole purpose of reading in the image, I use an anonymous object.
Otherwise, if the File were to have some future use, I would have created the File before, set it equal to a variable, and then used it in the read() method.

If you're not sure whether you're going to use an object again, it's best to simply assign it a pointer variable and play it safe.


Caleb

 
It wasn't my idea to go to some crazy nightclub in the middle of nowhere. I just wanted to stay home and cuddle with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic