Would it be possible to call this generic method? [closed] - java

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 7 years ago.
Improve this question
Given the following method of a class which doesn't have type T defined:
public <T> T get(java.lang.String name) { /* compiled code */ }
Would it be possible to invoke this, and how?

Yes. Just call it with an explicit type argument:
foo.<Integer>get("something")
I'm not terribly fond of how type arguments are expressed in Java, but they're perfectly doable. See the Java Generics Tutorial for another example.

Related

why java main method parameter name is args? [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 2 years ago.
Improve this question
i know method
signature use parameter,
and method use arguments when method call.
so i don't know why java main method parameter name 'args' is not 'param'
I am sorry that I am not good at English.
Just a variable name, you can use any name that meets the Java variable naming requirements
You can use any name for that, but "args" is short for "arguments". Some people prefer "parameter", some "argument". See also: "Parameter" vs "Argument"
It's not a matter of choice, it's about the meaning of the words: an argument is not a parameter
main(String args)
args is the method argument
main(null)
null is the parameter by which the method is invoked
See https://stackoverflow.com/a/1788926/1575188

Set interfaces in Java [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
What is the best way to implement a set interface in Java? Or more specifically, what is the best abstract data type to use when implementing a set interface? I need to create a set class in Java that implements a given set interface, but I'm wondering what the simplest way to do this is.
An interface example is java.util.Set, which is implemented by HashSet and TreeSet.

In java Programming this basic use [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 6 years ago.
Improve this question
I am new to Java Programming.
I want to understand the basic difference between the code below
this.customerPage.selectcustomerrecent(Customer);
this.customerPage = this.customerPage.selectcustomerrecent(Customer);
this.customerPage.selectcustomerrecent(Customer);
This piece of code means that customerPage is an instance variable and it has a method named selectcustomerrecent which takes argument of Class type Customer
this.customerPage = this.customerPage.selectcustomerrecent(Customer);
This is same as above and the only difference is that the response value of method selectcustomerrecent is reassigned to the instance variable customerPage.

C++ templates to Java Generics [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
How to write this piece of code in Java. What happens in C++ code when it extends from array and how to make something looks like it in Java. What way must I choose. Maybe I must make a class and extend from it or maybe something else?
template <typename T1, size_t N>
class tensor : public array<T1,N> {};
Not at all. Java generics are less powerful compared to C++ templates.
There is simply no way to express such a template in Java.

Can I obtain a Class Object for a local variable of a method using Reflection [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
If I have a variable defined in a method,can I get its Class Object using reflection
public void check(List<?> String> list){
Map<String,String> map // do something
}
Can i Obtain the Class Object to perform reflection for list and map variables,both are local variables
No, reflection does not expose local variables. Byte code analysis may help, but I don't know what you are trying to do.

Categories