casting

Typescript inferring Tuple as Array Incorrectly

混江龙づ霸主 提交于 2021-02-05 12:08:55
问题 Apologize for my English first. I have a function like function func(): [string, string[]] which returns a Tuple. However, when I implement the return statement like var test = ['text', ['foo', 'bar']]; return test; Typescript inferred my return type as (string | string[])[] instead of [string, string[]] . Did I missed something or should I need to cast the return object as Tuple explicitly everytime like return <[string, string[]]>['text', ['foo', 'bar']] . If yes then isn't it quite

Typescript inferring Tuple as Array Incorrectly

时光怂恿深爱的人放手 提交于 2021-02-05 12:06:04
问题 Apologize for my English first. I have a function like function func(): [string, string[]] which returns a Tuple. However, when I implement the return statement like var test = ['text', ['foo', 'bar']]; return test; Typescript inferred my return type as (string | string[])[] instead of [string, string[]] . Did I missed something or should I need to cast the return object as Tuple explicitly everytime like return <[string, string[]]>['text', ['foo', 'bar']] . If yes then isn't it quite

Cannot convert from int to boolean?

笑着哭i 提交于 2021-02-05 10:47:05
问题 public static void main(String[] args) { int [] newArray= new int [4]; int [] array = {4,5,6,7}; oddEven(array); newArray[0] = array[0]+array[1]+array[2]+array[3]; newArray[1] = array[0]*array[1]*array[2]*array[3]; } public static void oddEven(int [] oddEven) { for (int i=0; i<oddEven.length; i++) { // Cannot convert from int to boolean if (oddEven[i] % 2) } } Ignore what I'm trying to manage here. I'm only curious why it doesn't accept "if" statement in this for loop. As I stated it says

ConstraintLayout cannot be cast to android.widget.TextView

风流意气都作罢 提交于 2021-02-05 09:35:37
问题 I keep getting a runtime error when I try to launch an activity. Line where the error happen: private OnItemClickListener mDeviceClickListener = new OnItemClickListener() { public void onItemClick(AdapterView<?> av, View v, int arg2, long arg3) { textView1.setText("Csatlakozás..."); String info = ((TextView) v).getText().toString(); // <-- ERROR HERE String address = info.substring(info.length() - 17); Intent i = new Intent(DeviceListActivity.this, MainActivity.class); i.putExtra(EXTRA_DEVICE

Cast a property to its actual type dynamically using reflection (where actual type is generic)

我是研究僧i 提交于 2021-02-05 09:17:06
问题 This is a slightly different question asked here. I modified the same code into my needs like below: using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace cns01 { class Program { public class ClassA<T> { public int IntProperty { get; set; } = 999; } public class ClassB<T2> { public ClassA<int> MyIntProperty { get; set; } public ClassA<string> MyStringProperty { get; set; } } static void Main

Dynamic cast at runtime

笑着哭i 提交于 2021-02-05 09:12:15
问题 Is there a way to dynamically cast at runtime like the following pseudo code: foreach (DataRow row in table.Rows) { foreach (DataColumn col in table.Columns) { if (row[col] != DBNull.Value) { Type type = col.DataType; type cellContent = (type)row[col]; //Pseudo-Code } } } I´ve been searching the web and not found anything. There´s object obj = Activator.CreateInstance(type); , but then I´m still stuck with an object and can´t use specific type methods with it. Also I need a cast of an

Dynamic cast at runtime

六眼飞鱼酱① 提交于 2021-02-05 09:11:42
问题 Is there a way to dynamically cast at runtime like the following pseudo code: foreach (DataRow row in table.Rows) { foreach (DataColumn col in table.Columns) { if (row[col] != DBNull.Value) { Type type = col.DataType; type cellContent = (type)row[col]; //Pseudo-Code } } } I´ve been searching the web and not found anything. There´s object obj = Activator.CreateInstance(type); , but then I´m still stuck with an object and can´t use specific type methods with it. Also I need a cast of an

Should I cast void** return in Visual Studio

送分小仙女□ 提交于 2021-02-05 06:56:25
问题 I compile some code with visual studio 9.0 (2008). The behave as expected, but when I allocate some 2D array with some hand made functions, Visual-Studio generates some C4133 warning: void ** alloc_2d(int w, int h, size_t type_size); void free_d2(void ** mem); int main (void) { float ** data; /* Here is generated a C4133 warning: "incompatible type from void ** to float **" */ data = alloc_2d(100, 100, sizeof **data); /* do things with data */ /* free data */ free_2d(data); return 0; } I

how does c++ multiple inheritance casting work?

只谈情不闲聊 提交于 2021-02-05 06:00:16
问题 This question helped me to understand a bit, but my question is slightly different from theirs. Basic typecasting as I understand it in c++ involves reinterpreting a structure in memory, as a different structure. For example: class Building{int sqFootage;}; class Office : public Building{int cubicles;}; int main(int argc, char** argv){ Office *foo = new Office(); /*The cubicles member appears after the sqFootage member on an Office, * so the foo pointer is really just a Building* with some

Implicit conversion of a numeric in mysql

不打扰是莪最后的温柔 提交于 2021-02-04 21:51:01
问题 table struct: CREATE TABLE `test_table` ( `pk_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(30) NOT NULL, `password` varchar(128) NOT NULL, `version` bigint(20) NOT NULL, PRIMARY KEY (`pk_id`) ) ENGINE=InnoDB AUTO_INCREMENT=18446744073709551601 DEFAULT CHARSET=utf8; data: /* -- Query: SELECT * FROM test_table -- Date: 2017-09-15 16:51 */ INSERT INTO `test_table` (`pk_id`,`name`,`password`,`version`) VALUES (10545342555594296735,'testabc','testabc',5); INSERT INTO `test_table