• 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

newInstance with arguments?

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
i�m learning to do thread pools and i�ve found some good examples, but there�s something i would like to know. All the examples i�ve seen so far when they use newInstance in order to give the thread the code to work, they always use it with no arguments. How could i use newInstace with a class whose constructor requires arguments? For example, my class queryListener, its constructor is like this "queryListener(Socket socketa, Socket socket b, String text)", how should i do the newInstance if i want the thread to run the code inside my class?
Thanks!
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand how you use newInstance. Where can I find such an example?
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gus Spain:
How could i use newInstace with a class whose constructor requires arguments? For example, my class queryListener, its constructor is like this "queryListener(Socket socketa, Socket socket b, String text)"

You can't (not directly from a Class)! But lucky for you there's reflection:
 
reply
    Bookmark Topic Watch Topic
  • New Topic