Declaring a constant in java [closed] - java

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I have come across something rather strange today. A java developer has declared a constant like this:
public final class Constants {
public static final String KEY_COLUMN = AbstractDataRow.standardiseColumnName("key");
... // rest of implementation
}
public abstract class AbstractDataRow implements IRow {
public static String standardiseColumnName(String columnName) {
return columnName.trim().toLowerCase();
... // rest of implementation
}
}
What is strange to me is that KEY_COLUMN calls a method from an abstract class.
Is this good practice?

answering your question.. Not really.
You could just as easy call that string into the method already defined.. then convert that string to lowercase.
send the string to the method instead of the method to the string.

Related

java composition to reduce code complexity [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 days ago.
Improve this question
Let us say there is a class LargeClass with 4k lines of code. I would like to reduce the file size to manage it better by extracting the code into some other classes.
class LargeClass extends SomeLibraryClass {
void featureOneLargeMethod1() {
}
void featureOneLargeMethod2() {
}
void featureOneLargeMethod3() {
}
void featureTwoLargeMethod1() {
}
void featureTwoLargeMethod2() {
}
void featureTwoLargeMethod3() {
}
}
I could create two classes FeatureOne and FeatureTwo and move the corresponding methods into these new classes but the featureOneLargeMethod1() calls protected SomeLibraryClass.someLibraryMethod() which makes it impossible to move these methods. I was thinking of creating a wrapper interface that LargeClass implements and thereby FeatureOne and FeatureTwo class can access them. Any better approach in java or kotlin instead of creating the wrapper interface?

Which functional interface to use if method don't accept anything but return object of the class in java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 months ago.
Improve this question
I have one existing Java 7 method which accepts nothing but return class instance. I want to change it in java 8 using any existing functional interface but don't know what i can use here.
public NotificationPage infraSelection() {
......
return this;
}
Here NotificationPage is class name.
Maybe you can use the Supplier<T> interface?
It declares the method T get().

Constants in Interface [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I know there were a lot of questions about putting constants into interfaces, and that is a bad practice.
But I have a question, what if I have a class, where I want to define some sets of constants, but I want to have them in groups, is it a bad practice to have interface/class inside a class and define constants in there, so my constants are grouped?
e.g.
public class MyClass{
public final class A {
public static final String A = "a" ;
}
public final class B {
public static final String B = "b";
}
....
}
Yes you can have nested class to group the constants. It's really not a bad practice.
the question leads to a misleading. From my point of view the necessity to group constants is related to the fact that they regards different classes and so they must be putted int the correct classes; in other words this question can be an alarm about a not perfectly correct class design.

package structure for a class that contains only constants [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I have a realy simple class that contains only constants:
public class AppData {
public static long SPLASH_SCREEN_DELAY = 3000L;
}
my question is in which package should I place the class and what should be the name of this package?
For example...
Activities are placed in:
de.appname.ui.activities
domain classes in:
de.appname.model
a class that contains only static informations:
(???)
I know it's a design question and I need you suggestion.
Best regards
Stefan
You can keep this class under de.appname.util or de.appname.utility because all the constants will be utilized by other classes.

java: usage of instance keyword [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i came across to a java code with like this
public class TestClass{
private static volatile TestClass instance = null;
///...............
}
What is the use of instance and volotile in java, and i don't know why do we need to explicitly give null value to class.
This variable is meant to be used in a threadpool.
here is the definition of the volatile keyword:
http://www.javamex.com/tutorials/synchronization_volatile.shtml

Categories

Resources