casting

Why is a Ruby setter method returning a String rather than a Symbol as the last expression evaluated?

£可爱£侵袭症+ 提交于 2019-12-22 18:13:09
问题 Unexpected Return Value from Method: Expecting Symbol I have the following Ticket class: class Ticket VALID_STATES = %i[open closed invalid wontfix] attr_reader :status def status= new_state new_state = new_state.to_sym @status = new_state end end When passed a String rather than a Symbol, the setter method unexpectedly returns a String, even though the correct value is being returned by the getter method. For example: t = Ticket.new t.status = 'closed' #=> "closed" t.status #=> :closed It

Casting date in Talend Data Integration

﹥>﹥吖頭↗ 提交于 2019-12-22 13:56:21
问题 In a data flow from one table to another, I would like to cast a date. The date leaves the source table as a string in this format: "2009-01-05 00:00:00:000 + 01:00". I tried to convert this to a date using a tConvertType, but that is not allowed apparently. My second option is to cast this string to a date using a formula in a tMap component. At the moment I tried these formulas: - TalendDate.formatDate("yyyy-MM-dd",row3.rafw_dz_begi); - TalendDate.formatDate("yyyy-MM-dd HH:mm:ss",row3.rafw

Need clarification on AnyObject in Swift

不想你离开。 提交于 2019-12-22 13:12:52
问题 Before I start, I have already read the Swift documentation. I am still trying to comprehend what AnyObject actually is. Is it a base class for all objects/classes in Swift, as NSObject is in Objective C? If I create an array of type [AnyObject] and populate it with Movie class instances, that would mean that AnyObject is a base class of the Movie class right? let someObjects: [AnyObject] = [ Movie(name: "2001: A Space Odyssey", director: "Stanley Kubrick"), Movie(name: "Moon", director:

How to cast subclass object to superclass object

别说谁变了你拦得住时间么 提交于 2019-12-22 12:53:49
问题 i have 2 classes, called superclass and subclass, i tried to cast the subclass object to superclass, but its seems does not work when i want to use the subclass object from the superclass. Please help to explain. Thanks. These are the code:- public class superclass { public void displaySuper() } System.out.println("Display Superclass"); } } public class subclass extends superclass { public void displaySub() { System.out.println("Display Subclass"); } } public class Testing { public static

Defining explicit casting for generic types in C#

て烟熏妆下的殇ゞ 提交于 2019-12-22 12:27:25
问题 As part of an exercise I am trying to define a specific behavior for a generic class when used with a specific type. More precisely, I was wondering if it is possible to define a explicit casting operator for a generic type, i.e. from list<T> to int[] No, I know I could simply define a method that does the work, however this is not the goal of the exercise. Assuming the generic class list<T> I was trying to define the following explicit casting method class list<T> { ... public static

Precedence between member access from a pointer and cast

陌路散爱 提交于 2019-12-22 11:24:25
问题 If I have typedef struct{ int i; } typeB; typeA *p; then: What is the precedence between member access from a pointer and cast? (typeB *)p->i Is it actually ((typeB *)p)->i or (typeB *)(p->i) ? 回答1: An operator precedence table would show that a -> binds more tightly than the cast. typedef void *typeA; typeB b; typeA a = &b; (typeB *)a->i; /* wrong: attempt to dereference a void pointer */ ((typeB *)a)->i; /* ok */ A complete operator precedence table for your future reference is provided

Pointer to the start of an object (C++)

三世轮回 提交于 2019-12-22 11:06:07
问题 I need a way to get a pointer to the start of an object in C++. This object is used inside a template so it can be any type (polymorphic or not) and could potentially be an object that uses multiple inheritance. I found this article which describes a way to do it (see the section called "Dynamic Casts") using typeid and a dynamic_cast to void* in the case that T is a polymorphic type. This works perfectly well on MSVC, however on GCC (4.x) it seems to fall on its arse and spits out a compiler

How do I pass in a table parameter to this function?

人盡茶涼 提交于 2019-12-22 10:55:15
问题 I have a function organized like so: create function everything(waypoints waypoint) returns table(node int, xy text array) as $$ BEGIN create view results as ... return query (select * from results); END; $$ LANGUAGE plpgsql; And I have a table that has arguments organized the way the waypoint data type is structured. This table is not explicitly of type waypoint itself. The function gets created as it should, however, I am unable to call it by passing in my table like so: select everything

Resharper thinks that typecast is redundant, but without typecast the code does not work

时光毁灭记忆、已成空白 提交于 2019-12-22 09:57:10
问题 Iterating JsonData through foreach fetches IDictionary enumerator instead of IList one. foreach (var jsonEntry in jsonData) This causes my code to throw an error. InvalidOperationException: Instance of JsonData is not a dictionary LitJson.JsonData.EnsureDictionary () LitJson.JsonData.System.Collections.Specialized.IOrderedDictionary.GetEnumerator () LitJson.JsonData.System.Collections.IDictionary.GetEnumerator () Casting the object to IList causes Resharper to issue a warning "Type cast is

“possible loss of precision” is Java going crazy or I'm missing something?

这一生的挚爱 提交于 2019-12-22 08:59:28
问题 I'm getting a "loss of precision" error when there should be none, AFAIK. this is an instance variable: byte move=0; this happens in a method of this class: this.move=(this.move<<4)|(byte)(Guy.moven.indexOf("left")&0xF); move is a byte, move is still a byte, and the rest is being cast to a byte. I get this error: [javac] /Users/looris/Sviluppo/dumdedum/client/src/net/looris/android/toutry/Guy.java:245: possible loss of precision [javac] found : int [javac] required: byte [javac] this.move=