Questions tagged [generic-method]
180 questions
-1
votes
2 answers
Typing behavior of generic methods in Java
I am trying to understand the difference between static and non-static generic methods in Java:
public class Pair {
private K key;
private V value;
//the type of the _this_ object and the argument should be the same (just like in scompare)?…

fhussain
- 1
- 1
-1
votes
1 answer
Why does the empty() method (without any parameter) of java.util.stream.Stream in Java 8 contains a type parameter?
In Java 8's stream library, I found an interesting issue in same methods in java.util.stream.Stream:
static Stream empty()
As we can see that there is no parameter in the method signature. According to my understanding, in this case there…

Rui
- 3,454
- 6
- 37
- 70
-1
votes
1 answer
Create and show a Form instance based on a boolean using Generic Method
I have these classes :
internal partial class FBase : Form
{
public FBase() { InitializeComponent(); }
public FBase(bool owner) : this()
{
if (!owner) { this.Opacity = 0; Load += (s, e) => Close(); }
}
}
internal partial…

geek
- 346
- 6
- 14
-1
votes
1 answer
Bounding type parameters of generic methods with interfaces?
So I have 2 versions of the same method.
Version 1:
public static int countGreaterThan(T[] anArray, T elem)
{
int count = 0;
for (T e : anArray)
{
if (e > elem)
count++;
}
…

Patrick
- 87
- 1
- 7
-1
votes
1 answer
How to get the index for IList using Property Name of Class and object Index where Property names of both object and class Match?
I'm not sure if I'm explaining this correctly, or if the question is clear enough, but here's what I want to do.
I have created an object called index which stores the index of a elements in IList. Here's my ojbect index.
var index = new
…

user1828605
- 1,723
- 1
- 24
- 63
-1
votes
2 answers
When is a generic method appropriate and when it is not?
I am trying to have a deep understanding on when a generic method is to be written versus a non-generic method. Both the Collection interface as well as the Collections helper class has the addAll() method albeit with different signatures and the…

Geek
- 26,489
- 43
- 149
- 227
-1
votes
1 answer
generic methods to build factory pattern
I have 3 objects that have same properties with some differences each object have Id, Name, and TypeCode.
In database we have a first table containing Id, Name and TypeCode fields, and there is 3 other tables containing each one the corresponding…

user3540496
- 53
- 9
-1
votes
1 answer
Java Generic Methods
Original Question:
write the following method that returns a new ArrayList. The new list
ONLY contains the vowel elements from the original list which contains
an array of English characters (a,e,i,o,u).
This is what i have so far. I believe i…

user1789951
- 661
- 3
- 7
- 12
-2
votes
1 answer
Is there a way to handle generic function in go
I am new to go, and wanted to implement a scheduler that will recieve tasks(i.e interval + handler).
I got stuck in the part where I should get the handlers as go is a static language(I can't get a generic function signature).
I came up with the…

Gal Rotenberg
- 43
- 7
-2
votes
1 answer
Generic Method always returning NULL
I have a generic method (already developed by another developer way back) in my project for fetching cache; though I have values for the key the method still returns NULL.
Please take a look on the code:
public static C GetFromCache(string key)…

shashank joshi
- 11
- 3
-2
votes
1 answer
generic method does not compile in java
I am studying generic methods, i just come to this code, and I can not seem to figure out why the following line of code does not compile
public static T genMethod(T t) {
return t;
}

The Scientific Method
- 2,374
- 2
- 14
- 25
-2
votes
2 answers
Java generic methods difference between two arrays
I am trying to write a method that will find the difference between elements of two arrays of the same length and here is what I did until now:
public static T method(T[] array,T[] array1){
T[]difference;
difference…

javaprogrammewannabe
- 23
- 2
- 5
-3
votes
1 answer
C# Method Argument Always Receive as a Value, Not a Reference
I am working on Unity C# and trying to make my own Serializable Dictionary to use with ScriptableObject s. I am using a generic method and a generic indexed class to do that. I have an Add function that takes in a Key and a Value, both of any data…

Abdul Moiz Haroon
- 11
- 2
-3
votes
1 answer
Deserialize string in generic method c#
I need deserialize a string with a special encode in a class, like the funcion "JsonConvert.DeserializeObject<>" of NewtonSoft library, I wrote this code:
public void getMembersInfo()
{
Dictionary dict = new Dictionary

Manux22
- 323
- 1
- 5
- 16
-4
votes
1 answer
I want to implement generic java method passing argument as class object and defining method parameter as Class or T type
I want to achieve generic java method that it should be pass class object
in method parameter
E.g :
My method definition Here in different project class
public String getRtbAd(HttpServletRequest request, T userProfileClass,
…

anandchaugule
- 901
- 12
- 20