Win a copy of Svelte and Sapper in Action this week in the JavaScript 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Passing Class Reference to method

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello People

Please suggest me the use of passing class reference in a method

Here is the sample code from class A


And, then when it is called inside class C, it is referred to as ,


where B is another class



Please give your suggestions on this

Thanks

Nek
 
author
Posts: 23883
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Please give your suggestions on this



You want us to guess on what your code does? And why it needs a class object?

Henry
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Henry Wong wrote:You want us to guess on what your code does? And why it needs a class object?


I think it's more a case of they want someone to do their homework for them. This question has been posted on other Java forums.
 
Marshal
Posts: 70260
282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Tony, for noticing that. Please, Nek Thomas, look at this FAQ.
 
nek thomas
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply

Yes, I did post to other forums first, but after not getting suitable response I decided to post on javaranch



Please give your suggestions on this topic about use of Class Object in this particular example
 
Henry Wong
author
Posts: 23883
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Please give your suggestions on this topic about use of Class Object in this particular example



I don't get it. It's your code. Why don't you tell us why you need to do SQL on a Java class?

If I had to guess, maybe something related to reflection needs to be done, and it also needs some data from a DB?

Henry
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nek, you can pass a Class object to a method, there's no problem with that.
Your example is correct provided you know what you're doing.

What is your question?
 
nek thomas
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your suggestions

I have questions about the use of passing .class as a reference anywhere. And, please give suggestions of usage of .class in java code


 
Ranch Hand
Posts: 225
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are a couple of articles on reflection on java.sun.com:
  • Reflection API Tutorial
  • Advanced Language Topics: Using Java Reflection

  • They both have sample code using class objects.
     
    Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
    the value of filler advertising in 2020
    https://coderanch.com/t/730886/filler-advertising
      Bookmark Topic Watch Topic
    • New Topic