casting

Polymorphism vs DownCasting

≡放荡痞女 提交于 2019-12-12 03:35:07
问题 Let's say I have a Base class Employee and an derived class Manager , like below: class Employee { public: string Name; }; class Manager : public Employee { public: string Designation; }; While implementing some function like below: Employee* SomeFunction(bool SomeCondition) { Employee *Emp = NULL; if (SomeCondition) { //Code goes here : Both Implementation 1 and 2 work fine! } return Emp; } When SomeCondition is true, I want to return a non-null object of type Manager . In such a scenario,

Trying to convert IWebElement into a By element

[亡魂溺海] 提交于 2019-12-12 03:28:36
问题 Lets say I have a page object [FindsBy(How = How.Id, Using = "buttonSignIn")] public IWebElement BtnSignin { get; set; } I am trying to pass that into this method to convert the IWebElement into a By element. public void MoveAndClick(IWebElement element) { var findElement = driver.FindElement((By)element); Actions act = new Actions(driver); act.MoveToElement(findElement); act.Click(findElement); act.Perform(); } I know that this piece of code will work without casting the element into a By

MPAndroidChart Entry cannot be cast to BarEntry

我只是一个虾纸丫 提交于 2019-12-12 03:27:51
问题 I want to create a BarChart using MPAndroidChart but I get the following error java.lang.ClassCastException: com.github.mikephil.charting.data.Entry cannot be cast to com.github.mikephil.charting.data.BarEntry I first get the data from a different activity and use that. First activity: ArrayList<BarEntry> temperature = new ArrayList<>(); for (int i = 0; i < temp.length(); i++) { float temp_data = Float.parseFloat(temp.getJSONObject(i).getString("value")); float humid_data = Float.parseFloat

How do you instantiate a Map.Entry<K, V> array in Java? [duplicate]

余生颓废 提交于 2019-12-12 03:21:59
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Java Generics: Array containing generics I have a Java class which contains 2 methods which add and remove an element from an array. To make it generic it takes a subtype so it should be able to work on different types of objects. The problem is that when I instantiate it using MapEntry (where MapEntry is an implementation of java.util.Map.Entry) as the subtype. This results in a ClassCastException being thrown

How to typecast preprocessor (macros) to output int

穿精又带淫゛_ 提交于 2019-12-12 03:19:50
问题 I have a very simple macro for which I want to typecast its output to int only. How to do that? #define Numbits(A) (sizeof(A)*CHAR_BIT) I tried: #define int Numbits(A)({int val; val = sizeof(A)*CHAR_BIT; return val;}) but it also doesn't work 回答1: Are you saying that #define Numbits(A) (int)(sizeof(A)*CHAR_BIT) didn't work? 来源: https://stackoverflow.com/questions/31443484/how-to-typecast-preprocessor-macros-to-output-int

Warning in C: assignment makes integer from pointer without a cast

时光总嘲笑我的痴心妄想 提交于 2019-12-12 02:57:57
问题 I keep getting this error when compiling my program. This is just a small part of my code, so if needed I will provide the rest of the code. Any ideas on why this is occuring? void strip_quotes(char s[]) { if (s[0]=='"') s=s+1; if (s[strlen(s)-2]=='"') s[strlen(s)-2]=NULL; } 回答1: As Dave has already correctly pointed out the reason for the compiler error: s[strlen(s)-2]=NULL; /* = (void*)0 */ There is another bug in the code that won't cause a compiler error: if (s[0]=='"') s=s+1; the

Java Type Erasure: Rules of cast insertion?

三世轮回 提交于 2019-12-12 02:30:43
问题 The Java tutorial on type erasure doesn't seem to detail the specific rules of cast insertion by the compiler. Can someone please explain the specific rules that cause the transformation detailed by the tutorial (reproduced below): public class Node<T> { public T data; public Node(T data) { this.data = data; } public void setData(T data) { System.out.println("Node.setData"); this.data = data; } } public class MyNode extends Node<Integer> { public MyNode(Integer data) { super(data); } public

casting int to string in OData raises error

て烟熏妆下的殇ゞ 提交于 2019-12-12 01:59:31
问题 why the cast is not working here? http://services.odata.org/Northwind/Northwind.svc/Orders?$filter=startswith(cast(OrderID, 'Edm.String'),'1') it says: No coercion operator is defined between types 'System.Int32' and 'System.String'. 回答1: OData doesn't support conversion to and from string. It supports conversions between related entity types and between numeric primitive types only. See http://msdn.microsoft.com/en-us/library/dd541472(v=PROT.10).aspx and the castExpression paragraph. It's

c++ dynamic_cast over decorator instantiations fails

时间秒杀一切 提交于 2019-12-12 01:57:37
问题 I am trying to understand how decorator pattern works and how much I can "stretch" it to me needs. Following this example, I have extended classes XYZ. There exist derived classes "KLM" (from XYZ) Specifically, even though I have a decorator pattern, the derived decorator classes "KLM" have some functionality that does not show up in any of their base classes "XYZ", "D", "I" or "A". So while normally I would instantiate an object as I * inKLM = new L( new M( new K( new A ))); This would not

Getting 'java.lang.ClassCastException: java.lang.Long cannot be cast to java.util.Map' even when I'm not casting any Long

醉酒当歌 提交于 2019-12-12 01:54:33
问题 I'm trying to retrieve some data from Firebase using addChildEventListener() like this (code is in a Service ): aReference.child(requestID).addChildEventListener(new ChildEventListener() { @Override public void onChildAdded(DataSnapshot dataSnapshot, String s) { if (dataSnapshot.getValue() != null) { // error on the line below Map<String, String> nUser = (Map<String, String>) dataSnapshot.getValue(); userNameAU = nUser.get("uName"); Log.d("uName", userNameAU); } ... ... }); but I'm getting