• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Use of static classes

 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Trying to phrase this correctly!!!
Is it considered poor coding to call two methods of the same static class within one call.
For example.

Could there be a conflict in the way getNum() returns a value to be used by calc()?

Thanks!
Paul
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. Their are not conflicts with that. Do consider how the variable is being set though.
 
Sheriff
Posts: 17735
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would try to see if the code really wants to be refactored. Will calls to calc() always use getNum() as its parameter? If so, your code might be better looking like this:
int i = StaticClass.calc();
where the use of num is subsumed in the calc method. This may make the code a bit clearer/cleaner. Otherwise, I don't see a conflict in calling two static methods.
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Keohan:
Trying to phrase this correctly!!!
Is it considered poor coding to call two methods of the same static class within one call.
For example.

Could there be a conflict in the way getNum() returns a value to be used by calc()?

Thanks!
Paul



You mean static methods of a class, right?
Only inner classes can be static.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, only nested classes can be static. Only non-static classes can be inner classes. But yes, Paul must be talking about static methods, not static classes.
 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jim Yingst:
Well, only nested classes can be static. Only non-static classes can be inner classes. But yes, Paul must be talking about static methods, not static classes.


Yes, I was talking about static methods. Thanks for everyone's input.
 
Anderson gave himself the promotion. So I gave myself this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic