java: usage of instance keyword [closed] - java

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

Related

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().

How can multiple classes call one method that takes an instance of the calling class as a parameter? [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 6 years ago.
Improve this question
I want all my other objects to be able to call one common method. What should my shared method type signature for parameters look like?
public class appSocket{
public appSocket appSocket(TYPE genericInstance){
// Do something with genericInstance here
}
}
In other words, what should "TYPE" look like?
I think you're a bit confused. This just corresponds to the current object. There is no reason to ever say someObject.this.foo(). You'd just say someObject.foo(). You just pass in the object.

Getting to variable by using an inteface [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 7 years ago.
Improve this question
I've got an object that is interface, let's call it MyInterface something.
My interface is empty and is being implemented by two classes.
First on has one variable int x, and the second one two: int x, int y.
Variables are private but they've got "get" methods and i know them.
Is it possible to get to the variable of a class just by using "something"?
No, it's not possible (excluding reflection magic), unless you add a getX() method to MyInterface. Then, it's easy and it has the nice side-benefit of being a correct 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.

generics and static [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
In this book that I'm using to brush up, there's a relationship between generic methods and the static keyword. It appears that generic methods require that keyword, but I don't see why it's required?
Here's what the book did:
static <T> void myFunction(T [] myArray) {
//......
}
There is no requirement that generic methods be static. See Section 8.4.4 of the Java Language Specification for details (including links to other relevant parts of the spec). At the same time, there's nothing wrong with a generic method being static (or vice versa), either. It all depends on the design requirements.

Categories

Resources