Questions tagged [generic-method]
180 questions
0
votes
1 answer
ClassCastException using Mockito for generic method
I am using mockito to test a generic method. But i get a ClassCastException when i run the junit-test.
The method under test looks like this:
public ExampleClass {
public E randomObject(List list) {
E e = list.get(0);
…

user3637636
- 11
- 1
0
votes
1 answer
Creating async version of a generic method
I have this generic method for Deserializing a type
public static T Deserialize(string xmlString)
{
if (string.IsNullOrWhiteSpace(xmlString))
return default(T);
using (MemoryStream memStream = new…

Gaz83
- 2,293
- 4
- 32
- 57
0
votes
1 answer
C# invoke some method taking specified type as parameter in Generic Method
I am beginner of C#, and have problem that keep bothers me.
I will very appreciated if someone makes a solution.
I have a code something like :
public class SomeClass
{
public SomeClass()
{
GenericMethod(out result);
....
…

nolleh
- 107
- 2
- 10
0
votes
3 answers
Is it possible to return raw object from generic method?
research this method from Colletions class:
@SuppressWarnings("unchecked")
public static final Set emptySet() {
return (Set) EMPTY_SET;
}
Collections.emptySet() return `Set

gstackoverflow
- 36,709
- 117
- 359
- 710
0
votes
2 answers
Generic method won't work
My generic method gives casting exception.
java.util.LinkedHashMap cannot be cast to com.example.model.Student
main class
public static void main(String[] args) {
Map students = SampleClass.getStudents("students.json");
…

Darshana
- 2,462
- 6
- 28
- 54
0
votes
1 answer
Fake template method in MS Fakes Framework
I have an interface like this:
public interface IConfigManager {
T GetSetting();
}
On test project, I add fake for above dll, but cannot write fake method for it. Open the generated code, it looks like:
public class StubIConfigManager :…

Tu Tran
- 1,957
- 1
- 27
- 50
0
votes
1 answer
ObsoleteAttribute and Generic Methods
I'm adding a new generic Serialize method for my Serializer class. And old one must be obsolete.
[XmlRoot("a")]
public class A
{
[XmlElement("field")]
public string Field;
}
class Program
{
static void Main(string[] args)
{
…
0
votes
1 answer
Generic Method with generic return
Well, I have the following scenario:
public class Joins
{
public Expression> outerKeySelector;
public Expression> innerKeySelector;
public Expression

Eduardo Carísio
- 415
- 1
- 5
- 14
0
votes
2 answers
Understanding: public static int max(List list, Comparator super T> c) please
Im supposed to make a method that returns the max value of any list, I guess this is a generic method. But I dont understand the parameters, could anyone please explain me?
Also I made a iterator that i will use in the solution to run through the…

comodeque
- 95
- 1
- 2
- 7
0
votes
3 answers
Checking types in a generic method
I to know if it is possible to have an if statement in a method that will check the type of the generic used. In the case that got me thinking about this I want to handle a pretty basic Point2D class and a Point3D class differently. In the case of…

Danny
- 2,221
- 2
- 18
- 21
0
votes
1 answer
problems with generic methods
I am having problems with the following situation:
private static List extends Object> function1(final Collection extends Object>... collections) {
final List

user1414745
- 1,317
- 6
- 25
- 45
0
votes
1 answer
Correct XML comments for return value of generic method
I need create XML comment for return value of method Login. This method returns object type
of Result. This object contains session id if login was successful and if login was unsuccessful contains error message.
I don’t know how decribe this in…

imodin
- 821
- 3
- 12
- 23
0
votes
1 answer
Type safe equivalent of constraining a type parameter of a generic method to an unclosed type of given interface
In C# is it possible to constrain the type parameter of a generic method such that it is restricted to an unclosed type of an interface in a type safe manner?
Let me elaborate...
For example I have the following psuedo code:
public bool…

rheone
- 1,517
- 1
- 17
- 30
0
votes
2 answers
How do I get the type of an object passed though a generic method to use with foreach?
With the following code I'm trying to pass in 'CachedModel model' which has a list of items List. However the foreach doesn't like 'Item'. Nor does it like Item.GetType() or Type myType = Item.GetType(); foreach(myType…

mtntrailrunner
- 761
- 6
- 11
-1
votes
1 answer
Generic Type Return and Argument order in c#
I want to create a generic method like below :
Task PerformSomeAction(
Request request, string token)
where Response : ResponseModel
where Request : RequestModel;
is…

Jaydeep Shil
- 1,894
- 22
- 21