casting

ClassCast error: Java 7 vs Java 8

蓝咒 提交于 2019-12-17 15:51:14
问题 Is this a bug or feature? The following code runs fine in Java 7 but throws an exception in Java 8: The last command throws a ClassCast exception in Java8, all the "equivalent" commands above work the same way. The problem, I think, is that in Java 8, the compiler decides to use String.value(char[]) on the last line instead of String.value(Object) as in Java 7. I would think this should behave the same way for backward compatibility. Am I missing something? Note: As Marko suggested this is

ClassCast error: Java 7 vs Java 8

喜欢而已 提交于 2019-12-17 15:51:11
问题 Is this a bug or feature? The following code runs fine in Java 7 but throws an exception in Java 8: The last command throws a ClassCast exception in Java8, all the "equivalent" commands above work the same way. The problem, I think, is that in Java 8, the compiler decides to use String.value(char[]) on the last line instead of String.value(Object) as in Java 7. I would think this should behave the same way for backward compatibility. Am I missing something? Note: As Marko suggested this is

Convert OracleParameter.Value to Int32

旧巷老猫 提交于 2019-12-17 15:49:07
问题 I have a stored procedure call that goes like this: using (OracleConnection con = new OracleConnection(ConfigurationManager.AppSettings["Database"])) using (OracleCommand cmd = new OracleCommand("Package.Procedure", con)) { Int32 existsCount; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("successCount", OracleDbType.Int32, 0, ParameterDirection.InputOutput); cmd.Parameters.Add("BusinessId", OracleDbType.Int64, listRec.BusinessId, ParameterDirection.Input); con.Open(); cmd

Java Casting Interface to Class

你离开我真会死。 提交于 2019-12-17 15:48:06
问题 public class InterfaceCasting { private static class A{} public static void main(String[] args) { A a = new A(); Serializable serializable = new Serializable(){}; a = (A)serializable; } } Compilation succeed but Runtime exception Exception in thread "main" java.lang.ClassCastException: InterfaceCasting$1 cannot be cast to InterfaceCasting$A WHY COMPILATION SUCCEED? Compiler must known that serialiazable is not A? 回答1: As you point out, this will compile: interface MyInterface {} class A {}

Fixing BeanNotOfRequiredTypeException on Spring proxy cast on a non-singleton bean?

六月ゝ 毕业季﹏ 提交于 2019-12-17 15:46:07
问题 I'm having an issue with pulling a Spring bean from an application context. When I try; InnerThread instance = (InnerThread) SpringContextFactory.getApplicationContext().getBean("innerThread", InnerThread.class); I get; org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'innerThread' must be of type [com.generic.InnerThread], but was actually of type [$Proxy26] Without the specified class in the getBean() call I get a ClassCastException (which you can see in detail

Using AudioBufferList with Swift

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-17 15:44:52
问题 I have a bridging function in Swift, one of whose arguments in C is AudioBufferList * . In Swift this generates an UnsafePointer<AudioBufferList> . I've manage to deference the pointer by calling audioData[0] (is there a better way?). But I'm struggling with the next 2 tiers down: the .mBuffers array of AudioBuffer 's and their void * / UnsafePointer<()> .mData members. In C it would simply be Float32 *audioData = (Float 32*)abl->mBuffers[0]->mData; output = audioData[sampleNum]... In Swift

How to cast to a type alias in Go?

不问归期 提交于 2019-12-17 15:25:14
问题 See this playground snippet . Relevant code: type somethingFuncy func(int) bool func funcy(i int) bool { return i%2 == 0 } var a interface{} = funcy func main() { _ = a.(func(int) bool) // Works fmt.Println("Awesome -- apparently, literally specifying the func signature works.") _ = a.(somethingFuncy) // Panics fmt.Println("Darn -- doesn't get here. But somethingFuncy is the same signature as func(int) bool.") } The first cast works, by explicitly declaring the type. But the second cast

What are the rules for casting pointers in C?

别说谁变了你拦得住时间么 提交于 2019-12-17 14:59:31
问题 K&R doesn't go over it, but they use it. I tried seeing how it'd work by writing an example program, but it didn't go so well: #include <stdio.h> int bleh (int *); int main(){ char c = '5'; char *d = &c; bleh((int *)d); return 0; } int bleh(int *n){ printf("%d bleh\n", *n); return *n; } It compiles, but my print statement spits out garbage variables (they're different every time I call the program). Any ideas? 回答1: When thinking about pointers, it helps to draw diagrams . A pointer is an

What is printf's behaviour when printing an int as float?

折月煮酒 提交于 2019-12-17 14:45:03
问题 I am using dev cpp on windows7 to compile my code. int d = 0x12; char* e = (char*)&d; printf("%d %d\n", sizeof (int), sizeof (float)); printf("%p %p\n", &d, (float*)&d); printf("%p %p %p %p %p\n", &d, &e[0], &e[1], &e[2], &e[3]); printf(" %d | %x | %#1x | %#1x | %#1x |%p\n", d, e[0], e[1], e[2], e[3], &e[0]); getchar(); 4 4 0028FF40 0028FF40 0028FF40 0028FF40 0028FF41 0028FF42 0028FF43 18 | 12 | 0 | 0 | 0 |0028FF40 You an see that if I use %d for printing d, it is printing the 4 bytes of e

What is printf's behaviour when printing an int as float?

萝らか妹 提交于 2019-12-17 14:43:22
问题 I am using dev cpp on windows7 to compile my code. int d = 0x12; char* e = (char*)&d; printf("%d %d\n", sizeof (int), sizeof (float)); printf("%p %p\n", &d, (float*)&d); printf("%p %p %p %p %p\n", &d, &e[0], &e[1], &e[2], &e[3]); printf(" %d | %x | %#1x | %#1x | %#1x |%p\n", d, e[0], e[1], e[2], e[3], &e[0]); getchar(); 4 4 0028FF40 0028FF40 0028FF40 0028FF40 0028FF41 0028FF42 0028FF43 18 | 12 | 0 | 0 | 0 |0028FF40 You an see that if I use %d for printing d, it is printing the 4 bytes of e