Thread Rating:
  • 390 Vote(s) - 2.76 Average
  • 1
  • 2
  • 3
  • 4
  • 5
type-switch で Array-of 、HashTable-of を判別したい
12-26-2012, 07:13 PM,
type-switch で Array-of 、HashTable-of を判別したい
type-switch でクラス型の判定を行う際、


Array-of int も、Array-of String も同じように扱いたいのですが、
type-switch では CASE 文をパラメタの数だけ用意しなければいけないのでしょうか。
12-27-2012, 04:40 PM,
RE: type-switch で Array-of 、HashTable-of を判別したい
type-switch は isa 比較なので、パラメータの違う型を同じように扱うのは難しいと思います。

12-28-2012, 01:39 PM,
RE: type-switch で Array-of 、HashTable-of を判別したい
type-switch lets you check the type of something and bind a local variable to the type, so you use type-switch to check for each specific type, and write specific code for Array-of int or Array-of String.

It is possible to write the code that looks at the type of the parameters in a ParameterizedType, so you can use type-of to get the type of your object, and then do type-switch on that Type to see if it is a ParameterizedType and then look at ParameterizedType.positional-type-parameters and ParameterizedType .keyword-type-parameters. But if you do not cast the object to a specific type then you will still be doing "any" operations, which are slow, but if that is OK for your use then you can use that technique to write more generic code.

Possibly Related Threads...
Thread Author Replies Views Last Post
  Array-of が CDEで認識されない? umemura 1 2,494 04-04-2014, 06:28 PM
Last Post: twada
  #t , any , Type の違いは? umemura 3 3,773 09-17-2013, 08:05 PM
Last Post: umemura
  Array-of とSet-of の違い yosmas 2 4,003 08-18-2011, 05:09 PM
Last Post: yosmas
Forum Jump:

Users browsing this thread:
1 Guest(s)

MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1017 - Can't find file: 'mybb_threadviews' (errno: 2)
INSERT INTO mybb_threadviews (tid) VALUES('680')