首页 \ 问答 \ 泛型,ToArray等(Generics, ToArray etc)

泛型,ToArray等(Generics, ToArray etc)

我们有一个C#代码库,我们必须在Java上部署。

我们正在创建一个读取C#并编写Java的迁移引擎。

我们已经为我们的代码中使用的系统创建了类的存根类,并且正在实现它们。

当我在Java中使用List<T>时,我在实现ToArray遇到了问题。

根据我的理解,由于Java和C#在泛型方面的主要差异,因此无法知道泛型类的类型,因此无法创建类型化数组。

这是最终的,或者你们中的任何人都知道在泛型类中执行ToArray的一些聪明的方法,而不是在这里或在构造函数中传递数组或类型作为参数。


We have a C# code base that we have to deploy on Java.

We are creating a migration engine that reads C# and writes Java.

We have created stub class for the classes from system that are used in our code, and are implementing them.

When I came to do List<T> in Java, I ran into problems while implementing ToArray.

For what I understand, because of the major deference between Java and C# in terms of generics, there is no way of knowing the type of the generic class, and thus no way of creating a typed array.

Is this final, or any of you know of some clever way of doing ToArray in a generic class without passing an array or a type as a parameter here or in the constructor.


原文:https://stackoverflow.com/questions/2334843
更新时间:2021-12-11 12:12

最满意答案

你的$pw_length包含一个string 。 对于你的-lt操作,你需要它是一个integer

解决方案:像这样投射你的变量。

[int]$pw_length = $NumberBox1.Text

要么

$pw_length = $NumberBox1.Text -as [int]

Your $pw_length contains a string. For your -lt operation, you need it to be an integer.

Solution: Cast your variable like this.

[int]$pw_length = $NumberBox1.Text

or

$pw_length = $NumberBox1.Text -as [int]

相关问答

更多
  • 特别是如果你已经使用了一个子类UserCreationForm ,我会说你应该只是添加验证。 您应该能够覆盖clean_password上的clean_password方法: def clean_password(self): password = self.cleaned_data.get('password1') if len(password) < 8: raise ValidationError('Password too short') return sup ...
  • DATALENGTH()返回SQL Server中的字节长度。 等效的Oracle函数是LENGTHB() ( 在此处记录 ): ALTER TABLE my_table ADD CONSTRAINT MY_TABLE_PASSWORD_CK CHECK (LENGTHB(password) >= 4) 但是,出于您的目的,我认为字符串长度在两个数据库中都适用,即Oracle中的LENGTH() (或SQL Server中的LEN() )。 DATALENGTH() returns the len ...
  • 你的$pw_length包含一个string 。 对于你的-lt操作,你需要它是一个integer 。 解决方案:像这样投射你的变量。 [int]$pw_length = $NumberBox1.Text 要么 $pw_length = $NumberBox1.Text -as [int] Your $pw_length contains a string. For your -lt operation, you need it to be an integer. Solution: Cast your ...
  • 像这样使用assert: /** * @ORM\Column(type="string", length=255) * * @Assert\NotBlank(message="Please enter your name.", groups={"Registration", "Profile"}) * @Assert\Length( * min=3, * max=255, * minMessage="The name is too short.", * ...
  • 您也可以使用正则表达式来验证长度在8到16之间的模式,允许大写和小写字母,数字,句点和下划线。 You can also use Regular Expression which will ...
  • function CheckLength(name) { var password = document.getElementById(name).value; if (password.length < 4) alert('should have miniumum 4 chars'); }
  • 它确实使密码更难破解。 这是因为组合效应。 密码越长,尝试成功找到密码的组合就越多。 在您的用例中不会有太大的性能损失。 唯一的缺点,如果有的话; 是用户必须选择更长的密码。 It does make the password harder to crack. This is because of the combinatorial effect. The longer the password the more combinations to try to successfully find the pa ...
  • 在调用auth.define_tables()之前,请按如下所示设置最小密码长度: auth.settings.password_min_length = 8 或者,您可以将IS_STRONG验证程序添加到密码字段,或将其默认的CRYPT验证程序替换为指定min_length=8的版本。 Before calling auth.define_tables(), set the minimum password length as follows: auth.settings.password_min_le ...
  • SHA-256显然有256位。 最小UTF-8字符长度是一个字节,即8位。 因此,任何长度超过256/8 = 32个字符的密码都很可能与较短的密码冲突。 这是你的意思吗? SHA-256 has 256 bits, obviously. The minimum UTF-8 character length is one byte, i.e. 8 bits. Therefore, any password longer than 256/8=32 characters is guaranteed extrem ...
  • 6个字符的密码很短,可能太短。 此外,拥有最大密码大小是没有意义的,因为您应该只存储一个哈希值(或更好的输出bcrypt,scrypt或PBKDF2)。 也就是说,它取决于系统如何处理密码,如果它是安全的。 例如,PIN通常约为4..6 位 。 它仍然非常安全,因为您的银行可能只允许您在PIN被阻止之前输入大约3到5个错误的PIN条目。 如果您使用密码作为密钥来加密数据,而无需系统来控制对所述数据的访问(将文件加密到可以被盗的硬盘上),那么6个字符就会很短。 您将需要一个完整的密码和密钥派生方案,以使加密容 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)