Possible to have a function thats not a method in java? -
in java program i'm writing i’m finding i’m clogging main()
method lot of code make hard understand/read. due lot of error checking i’m doing. result want write quick function going used 1 method improve readability.
is writing method within class option or there other alternatives?
is writing method within class option or there other alternatives?
it depends:
if methods should belong class, should declared
private
orprotected
methods in class, depending if class can inherited or not.if methods should reused in other classes, better move utility classes
public
. example, check ifstring
empty , validating if notnull
. note example there methods covering these validations in utility classes apache common langs, explicitelystringutils#isempty(string)
.
by way, java has methods, no functions.
Comments
Post a Comment