generic-method Questions
4
Solved
I'm using reflection to find the generic method for Newtonsoft JsonConvert.DeserializedObject<T> but am finding that it's returning an ambiguous match for the non-generic version JsonConvert....
Genus asked 24/10, 2018 at 9:23
6
Solved
I have an abstract class that has a generic method and I want to override the generic method by substituting specific types for the generic parameter. So in pseudo-code I have the following:
publi...
Hest asked 18/3, 2011 at 0:19
4
Solved
The following noGood method gives a compilation error because it omits the formal type parameter immediately before the return type T.
public static T noGood(T t) {
return t;
}
Could somebody ...
Transcurrent asked 10/9, 2018 at 14:4
2
Is there a way in Java to return different types with one declaration of a method?
public Object loadSerialized(String path) {
Object tmpObject;
try {
FileInputStream fis = new FileInputStream...
Veiling asked 21/12, 2017 at 18:52
5
Solved
Here's a question, this first code listing compiles just fine (JDK 1.6 | JDK 1.7):
ArrayList<String> a = new ArrayList<String>();
String[] s = a.toArray(new String[0]);
However, if I...
Venetian asked 13/6, 2012 at 3:10
2
Solved
The following java code works fine.
public static void main(String[] arg){
JPanel p = (new JPanel());
p.add( new Object(){
JButton f(JButton x){
x.setEnabled(false);
return x;
}}.f(new JButt...
Solo asked 9/4, 2017 at 18:39
2
I'm trying to use generic methods in Dart (1.22.0-dev.10.3). Here is a simple example:
abstract class VR<T> {
VR();
bool foo<T>(T value);
}
class VRInt extends VR<int> {
VRI...
Credential asked 2/2, 2017 at 14:15
3
Solved
Please check the following codes segments:
public interface ICountable { }
public class Counter<T>
where T : ICountable
{
public int Count(IEnumerable<T> items)
{
return 0;
}
pu...
Bean asked 16/12, 2015 at 10:44
4
Solved
I can't understand the difference between the two code snippets below. Can someone help me with a simple explanation?
First of all, I have to say that I have a lot of classes that extend a super c...
Crotchety asked 9/12, 2015 at 8:38
1
Solved
Why this code isn't showing any compilation error?
public class Generic
{
public static void main(String[] args)
{
Character[] arr3={'a','b','c','d','e','f','g'};
Integer a=97;
System.out.pri...
Coherence asked 5/7, 2015 at 14:58
1
Solved
Why does the following code compile?
The method IElement.getX(String) returns an instance of the type IElement or of subclasses thereof. The code in the Main class invokes the getX(String) method. ...
Electrothermal asked 16/4, 2015 at 9:2
5
Solved
I was learning Generics in Java and I came close to a very interesting piece of code. I know in Java it is illegal to add list of one type to another.
List<Integer> integerList = new ArrayLi...
Hesperian asked 20/8, 2014 at 9:1
5
Solved
C++ does not support virtual template methods. The reason is that this would alter the vtable whenever a new instantiation of such a method is made (it has to be added to the vtable).
Java in cont...
Ayesha asked 22/6, 2014 at 11:24
1
Solved
I faced with code, which compilation result was surprised for me.
public class Test3{
public static<K,V> Map<K,V> map(){return new HashMap<K,V>();}
}
class A{
static void f...
Godsend asked 16/3, 2014 at 15:5
5
Solved
My application defines several enums that include the [Flags] attribute.
I wanted to write a small utility method to check if a flag was set for any of those enums and I came up with the fol...
Endow asked 8/5, 2011 at 18:7
6
Solved
If you create a generic class in Java (the class has generic type parameters), can you use generic methods (the method takes generic type parameters)?
Consider the following example:
public class...
Floppy asked 1/8, 2013 at 18:15
3
Solved
I am studying Java generic feature and I am not sure how to explain the third line in the following main method:
public class Example4 {
public static void main(final String[] args) {
System.out...
Quotha asked 8/4, 2013 at 8:48
2
Solved
What I want to do is have a method that takes a generic type as a parameter with a constraint. However, the constraint's type also has a second generic type, but I want the method to work regardles...
Chasten asked 25/1, 2013 at 3:5
2
Solved
Possible Duplicate:
Type-parameterized field of a generic class becomes invisible after upgrading to Java 7
public class Test{
private String _canYouSeeMe = "yes";
<T extends T...
Brazilin asked 1/8, 2012 at 14:23
3
Solved
Suppose I've a generic method as:
void Fun<T>(FunArg arg) {}
Are this.Fun<Feature> and this.Fun<Category> different instantiations of the generic method?
In general, how does ...
Claudicant asked 23/4, 2012 at 10:40
3
Solved
Is it possible to write similar construction?
I want to set, somehow, default value for argument of type T.
private T GetNumericVal<T>(string sColName, T defVal = 0)
{
string sVal = GetSt...
Supposititious asked 27/3, 2012 at 13:25
4
I want to create a simple generic function
void Assign<T>(out T result)
{
Type type = typeof(T);
if (type.Name == "String")
{
// result = "hello";
}
else if (type.Name == "Int32")
{
...
Overstock asked 14/11, 2009 at 21:56
5
Solved
I have an abstract class :
abstract class Foo(...){
def bar1(f : Foo) : Boolean
def bar2(f : Foo) : Foo
}
multiple classes extend Foo and override the methods
class FooImpl(...) extends Foo{
...
Charmian asked 7/1, 2011 at 15:9
4
Solved
Either I'm too stupid to use google, or nobody else encountered this problem so far.
I'm trying to compile the following code:
public interface MyClass {
public class Util {
private static MyCl...
Kiernan asked 31/5, 2011 at 20:6
2
Solved
Ok so I'm a Java guy starting to use C# and I was coding and started making a generic method and what I wrote runs and compiles but it goes against everything I know about how generics should work ...
Methedrine asked 12/2, 2011 at 0:17
1 Next >
© 2022 - 2024 — McMap. All rights reserved.