casting

How to rotate a polygon around a point with Java?

假如想象 提交于 2020-01-03 20:05:17
问题 I'm creating a Canvas object ( lines, vertices, triangle, ...) and I would like to apply to them a rotation around a point. I can't use the rotate() method of Canvas because points are attached to GeoPoint on a Map, so if I use the rotate() method the all map is rotating ... The problem is that Canvas needs Point(int,int) and applying a rotation creates double because of cos and sin functions. So when I apply the rotation to the all points, because of casting double to int, I have some

How to cast from InputStream to AudioInputStream

做~自己de王妃 提交于 2020-01-03 19:32:06
问题 Is it possible to cast from an InputStream to an AudioInputStream? I want to play little sound files at certain events, so I made following SoundThread import java.io.*; import javax.sound.sampled.*; public class SoundThread implements Runnable{ private String filename; SoundThread(String filename) { this.filename = filename; } public void run() { try { InputStream in = ClassLoader.getSystemResourceAsStream("sounds/"+filename+".wav"); Clip clip = AudioSystem.getClip(); clip.open(

Is a dynamic_cast<> limited to direct casts along the inheritance hierarchy?

半城伤御伤魂 提交于 2020-01-03 19:07:23
问题 CODE struct A { }; // virtual details there, but left out struct B { }; // virtual details there, but left out struct C : A, B { }; // virtual details there, but left out C c; B& b = c; A& a = dynamic_cast<A&>( b ); // will this cast succeed at run-time? Note that I have left out the virtual details to keep the code simple. If dynamic_cast<> is limited to direct casts along the inheritance hierarchy, then I expect the code above to fail at run-time (because B& is unrelated to A&). However, if

Casting Objects to <T>-type

随声附和 提交于 2020-01-03 17:07:44
问题 I'm implementing List interface to a class which stores data in a <T> type array. This raises problems with methods that take Collection as parameters, since collection stores it's objects as Object . How can I transform Object to T ? Simple casting doesn't work. class MyCollection<T> implements List<T>{ T[] tab; MyCollection() { this.tab = (T[])new Object[10]; } public boolean addAll(Collection c){ for(Object o : c){ o = (T)o; for(int i = 0; i < tab.length; i++){ tab[i] = o; } } } } I'm

Casting Objects to <T>-type

天涯浪子 提交于 2020-01-03 17:07:12
问题 I'm implementing List interface to a class which stores data in a <T> type array. This raises problems with methods that take Collection as parameters, since collection stores it's objects as Object . How can I transform Object to T ? Simple casting doesn't work. class MyCollection<T> implements List<T>{ T[] tab; MyCollection() { this.tab = (T[])new Object[10]; } public boolean addAll(Collection c){ for(Object o : c){ o = (T)o; for(int i = 0; i < tab.length; i++){ tab[i] = o; } } } } I'm

How is it possible to dynamically cast to a Type that is named in a string with Swift 2.0?

若如初见. 提交于 2020-01-03 17:03:37
问题 I need to cast a return value to a specific type that I need to keep dynamic, like let cellType = "CellTypeToBeResolved" cell = (tableView.dequeueReusableCellWithIdentifier("myID") as? CellTypeToBeResolved)! How is this possible in Swift 2.0? Thnx! 回答1: You can't do it, because Swift is (deliberately) missing not one but two pieces of the puzzle: You can't turn a string into a class. More important, you can't cast down to a class expressed as a variable. The class to cast down to must be a

What happens to casts using generics - (T)object - at run-time in Java?

与世无争的帅哥 提交于 2020-01-03 16:52:33
问题 As far as I understand, Java Generics erases all the information concerning the parameter type T in the generic method (or in the generic class). That's why we can't use new expression, such as new T() instanceof expression, such as if(obj instanceof T) inside a generic method. My question is how the parameter type T works inside a generic method when it comes to casting. For example, I have 3 simple classes here: public class People { String name; public String getName() { return name; }

Passing a constant integer when function expects a pointer

…衆ロ難τιáo~ 提交于 2020-01-03 13:08:09
问题 What's the best/most cannonical way of passing in a constant integer value to a function that expects a pointer? For example, the write function write (int filedes, const void *buffer, size_t size); Let's say I just want to write a single byte (a 1), I would think this: write (fd, 1, 1); but I obviously get the warning warning: passing argument 2 of 'write' makes pointer from integer without a cast I know I can do int i = 1; write (fd, &i, 1); but is that necessary? What's the most correct

reinterpret_cast<char*>(p) or static_cast<char*>((void*)p)) for bytewise pointer difference, which is better?

最后都变了- 提交于 2020-01-03 11:02:55
问题 Is there any difference between the following three casts for extracting raw byte pointers for use in pointer arithmetic? (assume a platform where char is 1 byte.) static_cast<char*>((void*)ptr)) reinterpret_cast<char*>(ptr) (updated) or: static_cast<char*>(static_cast<void*>(ptr)) Which should I prefer? In more detail... Given pointers to two member objects in a class, I would like to compute an offset from one to the other, so that I can reconstruct the address of one member given an offset

reinterpret_cast<char*>(p) or static_cast<char*>((void*)p)) for bytewise pointer difference, which is better?

点点圈 提交于 2020-01-03 11:02:36
问题 Is there any difference between the following three casts for extracting raw byte pointers for use in pointer arithmetic? (assume a platform where char is 1 byte.) static_cast<char*>((void*)ptr)) reinterpret_cast<char*>(ptr) (updated) or: static_cast<char*>(static_cast<void*>(ptr)) Which should I prefer? In more detail... Given pointers to two member objects in a class, I would like to compute an offset from one to the other, so that I can reconstruct the address of one member given an offset