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.
Related
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 8 months ago.
Improve this question
While using streams, I learned how to handle exceptions using functional interfaces and wrapper functions.
If so, what is the best way to structure the package?
Is it defined together in the class where stream is used? Or should I create a separate common class and define the wrapper function in it?
Thanks!
I think it depends. If you have one instance of using this technique, then it probably makes sense to simply use an functional interface and a wrap function that are part of the class which utilizes it. If you are using this same pattern in several places (and they all have the same function interface signature) then you can define the functional interface at the package level and put the wrap function in a utility class.
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 recently took an online test for an interview. It was a multiple choice test and I got the following question:
Q) In a Java class we can write multiple methods with same name and
different method signatures, this is called_____________
a) function overriding
b) function overloading
c) none of the above
I know that it is method overloading but in the options it's not there
Is the term function overloading equivalent to method overloading in Java?
From a pragmatic point of view, I would go with function overloading.
But when thinking in pure Java terms, the one and only term is methods. Java does not know functions, only methods. Besides the interface Function.
Coming from there, it is not really clear if "none" or "function overloading" is the correct answer.
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.
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 possible I would like to know what class provides input and output streams? Is it Object or System class? I am asking this because every class inherits Object class. This is a bit confusing to me.
Input and Output operations are performed by the reader class and it's sub-classes. Object is a base class which provides some "usefull" methods such as equals() and toString().
i don't know what exactly is your confusion , but i think its java.io.OutputStream and java.io.InputStream both are interfaces , based on what Stream you use , there definition in Stream class changes. i suggest you read some basic books and gets your fundamental of OOP strong.
and make full use of
Reference doc
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 9 years ago.
Improve this question
I have been trying for a while, but now I'm wondering if I can. Is it possible for a method in an interface to return a variable or an array without needing two interfaces or methods(if possible)?
Every method has to specify a return type and stick with it. There are no "union types" like "returns a String or an int[]".
If you really have a method that can return two different things, you can
make a wrapper type (StringOrIntArray) that can hold both
or
have the method return Object which can be pretty much anything, including arrays, and use instanceof at the caller to see what you got.
Both options are not particularly attractive. Maybe take a step back and rethink the bigger picture.
What is wrong with
interface Foo{
int foo1();
//or....
int[] foo2();
}
?