Questions tagged [generic-method]
180 questions
2
votes
1 answer
What does before the return type of a method mean?
The following method returns a List composed of T type elements:
public List getList() {
return new ArrayList();
}
In the signature we have List. The List makes sense, because that is the type of the return value. What is…

James Taylor
- 413
- 4
- 6
2
votes
1 answer
Generic Method to Populate a List Cannot Create T()
I have the generic method below which would serve its purpose if it worked! But the items.Add(new T(mo)); part wont compile because im using a constructor. Can anyone help?
private List Items(string query) where T : new()
{
…

Jimbo
- 22,379
- 42
- 117
- 159
2
votes
2 answers
Use Reflection to call generic method on object instance with signature: SomeObject.SomeGenericInstanceMethod(T argument)
How do I call SomeObject.SomeGenericInstanceMethod(T arg) ?
There are a few posts about calling generic methods, but not quite like this one. The problem is that the method argument parameter is constrained to the generic parameter.
I know that…

smartcaveman
- 41,281
- 29
- 127
- 212
2
votes
1 answer
Is S extends ArrayList of S a useful construct in the language or just a grammar side-effect
Can anything other than null be added to this s1 ? ( and be safely assigned to temp )
Is
>
a useful construct in the language or just a grammar side-effect? Am I correct in interpreting S as an ArrayList that can only hold…

Gonen I
- 5,576
- 1
- 29
- 60
2
votes
1 answer
inference variable T has incompatible bounds Error
ArrayList detailArray = new ArrayList(Arrays.asList(shipDetail));
Sorter.QuickSort( detailArray );
And this is my Sorter class in which I was trying to do Implement some algorithms.
public class Sorter
{
public static

Anmol
- 91
- 1
- 3
- 10
2
votes
1 answer
Why do Java Generic Method Argument Classes Need to be Cast
I have a generic method:
public boolean saveRow(T row, Class rowClass) {
Mapper rowMapper = mappingManager.mapper(rowClass);
rowMapper.save(row);
return true;
}
And I would like to ditch the second parameter since I can infer…

Cristi
- 117
- 1
- 2
- 9
2
votes
0 answers
Generic CRUD with Sqlite-net Xamarin C#
I'm developin an App using Xamarin.Android in C#, and I'm using Sqlite-net to manage the database, for now I'm using a model class (Animal) to define the table fields:
[Table("Animais")]
public class Animal
{
[PrimaryKey, MaxLength(20)]
…

user3159043
- 197
- 1
- 1
- 16
2
votes
1 answer
Generic methods and type casting
I read the following question (and I would solve it the same way as the given answer): Passing derived type as argument to abstract class
But why is it not able to find the value attribute from the derived class? even if I add a type cast it is not…

wake-0
- 3,918
- 5
- 28
- 45
2
votes
4 answers
C# call Generic method dynamically
Given the following Interfaces:
interface IEntity
{
int Id{get;}
}
interface IPerson : IEntity
{
string Name{get;}
int Age{get;}
}
interface ITeacher : IPerson
{
string StaffId{get;}
}
interface IStudent : IPerson
{
string…

Soni Ali
- 18,464
- 16
- 44
- 53
2
votes
3 answers
Java compiler is not agreed with safety of a generic method call
I'm working on some set of abstractions representing an SQL result set and have written this methods:
public interface Column{
//some methods
}
public class SqlRowExtractor{
public void doExtraction(){
Collection> cols…

St.Antario
- 26,175
- 41
- 130
- 318
2
votes
6 answers
Are mutiple methods recommended when returning different types?
I'm returning values from an Entity object. Some of them are String typed and some are not. Right now, I did a quick solution as follows.
private String GetStringValue(Entity entity, String attribute, String substitute = "")
{
…
user1675891
1
vote
2 answers
Dart generics method not recognizing type
I have an abstract base class validator with a method which takes a generic type as parameter.
I will be passing generic type parameter to base class from the subclass inheriting the base class.
Base Class:
abstract class BaseValidator {
bool…

Gowtham K K
- 3,123
- 1
- 11
- 29
1
vote
1 answer
Which version of GetAttributeValue of the 'HTML Agility Pack' is used when calling from PowerShell with the second parameter $null?
I am writing a PowerShell script to work in Windows 10. I am using the 'HTML Agility Pack' library version 1.11.43.
In this library, there is a GetAttributeValue method for HTML element nodes in four versions:
public string GetAttributeValue(string…

Ilya Chalov
- 149
- 2
- 9
1
vote
2 answers
How to call a generic method in generic service?
I have a generic class that one of its fields is a generic service. In this class, I have a method with the name InitialQueue that its purpose is to call one of the generic service methods that I give it to InitialQueue method. My problem is that I…

Farshad Shahsavari
- 31
- 6
1
vote
2 answers
"No overload for method 'ToString' takes 1 arguments" in a C# generic method
I am trying to write a C# generic method that accepts nullable decimal and double values and converts them to a string representation.
I am getting the error "No overload for method 'ToString' takes 1 arguments" although I am accessing .Value of the…

lukin155
- 63
- 8