Having being taught during my C++ days about evils of the C-style cast operator I was pleased at first to find that in Java 5 java.lang.Class had acquired cast method.
I thought that finally we have an OO way of dealing with casting.
Turns out Class.cast is not the same as static_cast in C++. It is more like reinterpret_cast. It will...
I have never used Informix before and I'm trying to write a query that will return records over the last 365 days.
Here is the query I have been trying to use:
Select * from Visit where vis_mod_dt between today-365 and today;
That returns no records even though I know that there is data for the last 365 days. I am guessing that the ...
Hi to all.
I have this scenario:
A SQL Server table myTable with field1, xmlField (nvarchar(50) and xml sql server data type)
Linq to entities
Now I'd like to get a query like this:
SELECT Field1, XmlField
FROM MyTable
WHERE CAST(XmlField AS nvarchar(4000)) = '<myXml />'
Obviously this is a correct query in SQL Server but I can't...
I have a object graph that is setup like this
Clients
string Name
List[Address] Addresses
I would like to cast this to
MyClients: Clients
string Name
List[MyAddress] Addresses
MyAddress: Address
String City
I know that I can cast this by walking the whole object graph and in the given example that would not b...
I discovered the reason I was getting "Operation could destabilize the runtime" in a DynamicMethod I'm producing, and though I easily fixed it, it left me with a seemingly simple question:
How do I cast an object reference of type "Object" into a specific type, so that I can call methods from that type on the object reference?
Below ...
I am having trouble with a complex script which sometimes (About 2 or 3 times while calulating about 90'000 values), generates a '-0' and writes it into the database. I suspect it's a string (The values which are calulated can result in integers, floats or strings.)*
Is there any PHP calculation which might result in a '-0'?
* = Oh, ho...
I have a base class defined as:
Public MustInherit Class BaseRepository(Of T As Class)
and a class that inherits from this class, defined as:
Public Class CommunicationTypeRepository
Inherits BaseRepository(Of CommunicationType)
For testing purposes I have created a helper method that will use Moq to help fetching some ...
Here's the situation: I am using ILMerge to merge an assembly & all it's references into 1 .dll file using this method (custom.dll). I have an application which dynamically loads this assembly at runtime (program.exe). Both application & assembly use a common library (common.dll). Abstract class ClassX is defined in common.dll whilst...
I have a place in the code that used to say
const myType & myVar = someMethod();
The problem is that:
someMethod() returns const myType
I need to be able to change myVar later on, by assigning a default value if the object is in an invalid state. So I need to make myVar to be non-const.
I assume I need to make myVar be non-referen...
What's the most idiomatic way in Java to verify that a cast from long to int did not lose any information?
This is my current implementation:
public static int safeLongToInt(long l) {
int i = (int)l;
if ((long)i != l) {
throw new IllegalArgumentException(l + " cannot be cast to int without changing its value.");
}
...
I have a dictionary object that I am pulling data out of. The field is supposed to be a string field but sometime all that it contains is a number. I get the info using:
NSString *post = [[temp objectAtIndex:i] valueForKey:@"POSTDESCRIPTION"];
So it is going into a string object. However, when I try to assign that to a cell's text via...
I am working on a project that uses many web services. Many of them return the same class as a response. Right now, I am wanting to be able to pass the result from one web service in as a parameter to another. This isn't working though. When I try to implicitly cast it, it says it can't be implicitly cast. When I try to explicitly c...
Here's a thinned out version of the classes I have.
public abstract class BaseParent { }
public abstract class ChildCollectionItem<T>
where T : BaseParent
{
// References a third-party object that acts as the parent to both the collection
// items and the collection itself.
public T parent;
// References the collection to w...
In the Python documentation and on mailing lists I see that values are sometimes "cast", and sometimes "coerced". What is the difference?
...
Is there any reason to prefer static_cast<> over C style casting? Are they equivalent? Is their any sort of speed difference?
...
I have to pack and unpack a 16bit Int from/into a Ushort in VB.net
This is how I thought I could do it (doesn't work, gives me overflow exception)
'Pack Int16 into ushort '
Dim usPacked = CType(Data, UShort)
'unpack Int16 from ushort '
Dim unpacked = CType(data,Int16)
Thanks!
...
public Configuration(Node node, File file) {
HashMap<String, String> conf = (HashMap<String, String>) SerializationUtils.deserialize(new FileInputStream(file));
}
I understand why this gives an unsafe cast warning, but what's the best/accepted way to do this safely? Is there any good way?
...
Let's say you have yourself a class like the following:
public sealed class StringToInt {
private string _myString;
private StringToInt(string value)
{
_myString = value;
} public static implicit operator int(StringToInt obj)
{
return Convert.ToInt32(obj._myString);
}
public static im...
At some point in an algorithm I need to compare the float value of a property of a class to a float. So I do this:
if (self.scroller.currentValue <= 0.1) {
}
where currentValue is a float property.
However, when I have equality and self.scroller.currentValue = 0.1 the if statement is not fulfilled and the code not executed! I found o...
Hi I'm trying to convert from an int to a float in C and for some reason the cast changes the value and I'm not sure why. So:
fprintf (stderr, "%d,%d\n", rgbValues->green, (float)rgbValues->green);
produces two different numbers. Note that rgbValues->green is an int.
Any idea why this is happening?
Thanks
...