What is the meaning of the Java warning "Type safety: The cast from Object to List is actually checking against the erased type List"? I get it when I try to cast an Object to a type with generic information, such as in the following code:
Object object = getMyList();List<Integer> list = (List<Integer>) object;...
It seems that a List object cannot be stored in a List variable in C#, and can't even be explicitly cast that way.
List<string> sl = new List<string>();List<object> ol;ol = sl;
results in Cannot implicitly convert type ‘System.Collections.Generic.List’ to ‘System.Collections.Generic.List’
And then...
List<string> sl = new List<string...
Hi Guys,
Here is the problem I am having, I have a class that I want to use to store "properties" for another class, these properties simply have a name and a value. Ideally, what I would like is to be able to add typed properties, so that the "value" returned is always of the type that I want it to be.
The type should always be a pr...
OK, here we go again! Following on from my previous question on Converting to a Generic Type from String, I thought I would ask another Generics-related question!
This time, is there a way to enforce/limit the types that are passed to PRIMITIVE's? (bool, int, string, etc)
Now, I know you can limit the generic type parameter to a type o...
C++ 0x has template typedefs. See here. Current spec of C++ does not.
What do you like to use as work around ? Container objects or Macros ?
Do you feel its worth it ?
...
PHP, as we all know is very loosely typed. The language does not require you to specify any kind of type for function parameters or class variables. This can be a powerful feature.
Sometimes though, it can make debugging your script a painful experience. For example, passing one kind of object into a method that expects a different kind...
It is common knowledge that built-in enums in C++ are not typesafe.
I was wondering which classes implementing typesafe enums are used out there...
I myself use the following "bicycle", but it is somewhat verbose and limited:
typesafeenum.h:
struct TypesafeEnum
{
// Construction:
public:
TypesafeEnum(): id (next_id++), name("") {}
...
Hi there,
When compiling the following simpleType with the XJC compile (from the JAXB package)...
<xs:simpleType name="test">
<xs:annotation>
<xs:appinfo>
<jaxb:typesafeEnumClass/>
</xs:appinfo>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:enumeration value="4">
<xs:annota...
What does "type-safe" mean?
...
In my spring application context file, I have something like:
<util:map id="someMap" map-class="java.util.HashMap" key-type="java.lang.String" value-type="java.lang.String">
<entry key="some_key" value="some value" />
<entry key="some_key_2" value="some value" />
</util:map>
In java class, the implementation looks like:
priv...
Adding a service reference to a web service (this is all WCF) in Visual Studio produces some generated code including a client-side restatement of the interface being exposed.
I understand why this interface is generated: you might be consuming a 3rd party service and not have access to the actual interface.
But I do, and the two are n...
I have a custom class set up as a key that has two properties, X and Y
I have something similar to this:
Dim test As New List(of TestClass)
Dim key as New TestData
key._a = A
key._b = B
For Each a As TestClass In SomeCollection
If Not test.Contains(key) Then
'Do Stuff
End If
Next
My question is this: How does the .Contain...
Let's say I have a data object, but this object can hold one of several types of data.
class Foo
{
int intFoo;
double doubleFoo;
string stringFoo;
}
Now, I want to create an accessor. Some way to get at this data. Obviously, I could create multiple accessors:
public int GetIntFoo();
public double GetDoubleFoo();
public ...
I am curious to know why this is happening. Please read the code example below and the corresponding IL that was emitted in comments below each section:
using System;
class Program
{
static void Main()
{
Object o = new Object();
o.GetType();
// L_0001: newobj instance void [mscorlib]System.Object::.ctor()
...
I've just got back to MIDP development after some 4 years of .NET 2 and Java 5 and 6. During that time I got to like using enums quite a lot.
Enum is a language feature that allows a developer to have more confidence in some parts of his code, specially for being able to avoid or detect errors earlier (during compilation). Some other ad...
I had a brainbench exam recently, got high mark, but there were a couple of questions which were hard for me. Maybe it's because english is not my native language... One of the questions is:
Which one of the following describes type-safety?
A programming construct used to ensure the security of reference and value types in the CLR ...
When I wish to bind a control to a property of my object, I have to provide the name of the property as a string. This is not very good because:
If the property is removed or
renamed, I don’t get a compiler
warning.
If a rename the property
with a refactoring tool, it is
likely the data binding will not be
updated.
I don’t get an er...
Is there any way to emulate a structure class in PHP? ie a class which passes by value and not by reference, so it can still be type hinted...
And if so, what different techniques could be used? What's the best technique?
If this is possible you could obviously create a fully type safe layer for PHP, are there such layers? Has anyone h...
Here is my code:
Object[] data = GeneComparison.readData(files);
MyGenome genome = (MyGenome) data[0];
LinkedList<Species> breeds = (LinkedList<Species>) data[1];
It gives this warning for the LinkedList:
Type safety: Unchecked cast from Object to LinkedList<Species>
Why does it complain about the linked list and not MyGenome?
...
I'm trying to override equals() for a parametrized class. How can I make sure that this parameter is the same?
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
* Because this is commutative, `Tuple(a0, a1)` is the same as `Tuple(a1, a0)`
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true...