// legacy code
void setCacheValue(String name, Object value){
getServletContext().setAttribute(name, value);
}
Object getCacheValue(String name){
return getServletContext().getAttribute(name);
}
// so I want to use generic for "type safety"
// first, set method seems working perfectly
<T> void setCacheObject(String name, T va...
Greetings. This is my first post in this site.
I thought that because of type erasure, one could not expect the following code to compile, and indeed, it did not compile on an earlier version of Eclipse. My understanding was that instanceof was a run-time operator and could not know about the generic type which would be, by run-time, ...
I have an object which is creating several event handlers using lambda expressions, and I need to remove all handlers created in that object in one time.
I'm trying to create some unified static object which will 'know' which handler relates to which object and event if event handler was created through this static object.
I tried some...
Since I've a similar function for 2 different data types:
func GetStatus(value uint8) (string) {...}
func GetStatus(name string) (string) {...}
I would want to use a way more simple like:
func GetStatus(value interface{}) (string) {...}
Is possible to create a generic function using an interface?
The data type could be checked usin...
Hello,
from some code I found in Sacha Barbers free mvvm framework chinch I saw this:
return new DispatcherNotifiedObservableCollection<OrderModel>(
DataAccess.DataService.FetchAllOrders(
CurrentCustomer.CustomerId.DataValue).ConvertAll(
new Converter<Order, OrderM...
I wont to create a User Control based in gridview that have the edit add delete incorporate,
the problem is these:
In the admin part of my web site i have to repeat the same action for view add delete update the data for different datasource.
I wont to create a generic gridview that have incorporate these action.
The gridview can take...
this is my method: GetListItemsPainted<T>(List<T> list)
and i don't know what type is that list of,
how can i create new list that would have the passed list type?
something like this:
List<list.GetType()> newList = new List<list.GetType()>();
how can i cast my list to the real type so i would have all his properties etc.?
thanks
...
If an escape character (or most other characters < 0x20) is sent to the generic / text only printer it gets printed as a period. Using the code in the WinDDK is it possible to 'correct' this behaviour so that it passes it through unmodified?
The general scenario for this is that some application ('user app') outputs a document to a win...
I have a generic class that is also a mapped super class that has a private field that holds a pointer to another object of the same type:
@MappedSuperclass
public abstract class MyClass<T extends MyIfc<T>>
implements MyIfc<T>
{
@OneToOne()
@JoinColumn(name = "previous", nullable = true)
private T previo...
In the Java Generic Book, while contrasting the difference between C++ Templates and Java Generic says:
In C++, a problem arises because >>
without the space denotes the
right-shift operator. Java fixes the
problem by a trick in the grammar.)
What is this trick?
...
I have a generic function foo, which accepts any type and prints them out.
public static <T> T foo(T... arg) {
List<T> foo = Arrays.asList(arg);
for (T t : foo) {
System.out.println(t);
}
return null;
}
How do I make sure that the arguments received are of only 1 type. For example, {1,'a',3} should be invalid. ...
I want to have an extension method for XElement/XAttribute that allows me to apply a "ValueOrDefault" logic - perhaps with various slightly different implementations: ValueOrNull, ValueOrDefault, NumericValueOrDefault (which validates if the value is numeric), but I want to constrain these methods so that they can only work with ValueTyp...
Hello. We have encountered some strange things while calling reflected generic delegates. In some cases with attatched debuger we can make impossible call, while without debugger we cannot catch any exception and application fastfails.
Here is the code:
using System;
using System.Windows.Forms;
using System.Reflection;
namespace Gener...
Hello,
Let's imagine really simple game... We have a labirinth and two players trying to find out exit in real time through internet.
On every move game client should send player's coordinates to server and accept current coordinates of another client. How is it possible to make this exchange so fast (as all modern games do).
Ok, we ...
Hello, I just hit a situation where a method dispatch was ambiguous and wondered if anyone could explain on what basis the compiler (.NET 4.0.30319) chooses what overload to call
interface IfaceA
{
}
interface IfaceB<T>
{
void Add(IfaceA a);
T Add(T t);
}
class ConcreteA : IfaceA
{
}
class abstract BaseClassB<T> : IfaceB<T>...
Hey,
I appears to me as though there is a bug/inconsistency in the C# compiler.
This works fine (first method gets called):
public void SomeMethod(string message, object data);
public void SomeMethod(string message, params object[] data);
// ....
SomeMethod("woohoo", item);
Yet this causes "The call is ambiguous be...
In case of Java, we can get the path separator using
System.getProperty("path.separator");
Is there a similar way in Perl? All I want to do is to find a dir, immediate sub directory.
Say I am being given two arguments $a and $b; I am splitting the first one based on the path separator and joining it again except the last fragment and...
Hi
I want to create a generic list - but I want to specify the type at runtime - is there a way I can do this? using reflection perhaps?
Something like this...
Public Shared Sub create(ByVal t As Type)
Dim myList As New Generic.List(Of t)
End Sub
Thanks in advance
James
...
Hey guys I cant manage with this code. The idea is to return default English alphabet in case of erroneous create method execution. Thanks.
An idea to override explicit operator is good, but i cant imagine an implementation of casting.
namespace trie
{
class AlphabetFactory<T> where T: IConvertible
{
pub...
I meet a problem about type contraint of c# now.
I wrote a pair of methods that can convert object to string and convert string to object.
ex.
static string ConvertToString(Type type, object val) {
if (type == typeof(string)) return (string)val;
if (type == typeof(int)) return val.ToString();
if (type.IsSubclassOf(typeof(CodeObject)...