首页 \ 问答 \ Kotlin和泛型,用泛型数组实现抽象泛型类(Kotlin and generics, implementing abstract generic class with generic array)

Kotlin和泛型,用泛型数组实现抽象泛型类(Kotlin and generics, implementing abstract generic class with generic array)

我有以下抽象类

abstract class Vec2t<T : Number>(open var x: T, open var y: T)

由...实施

data class Vec2(override var x: Float, override var y: Float) : Vec2t<Float>(x, y)

到目前为止,一切正常

现在,我想为矩阵做类似的事情,这是我的抽象类

abstract class Mat2t<T : Number>(open var value: Array<out Vec2t<T>>)

应该通过实施

class Mat2(override var value: Array<Vec2>) : Mat2t<Float>(value)

但编译器抱怨Array<Vec2>

错误:(8,32)Kotlin:'value'的类型与在main.mat.Mat2t中定义的重写的var-property'public open var value:Array>的类型不匹配'

有人告诉我:

  • 当我覆盖它时,我无法更改var属性的类型(但实际上我并没有真正改变它,我用一个子类型覆盖它...是同样的事情吗?)
  • mat2.value = object : Vec2t<Float>() { ... }无效, Mat2t<Float>任何子类都不一定如此

我怎么能克服这些问题呢?

有没有办法让一个抽象的泛型类Mat2t与一个通用数组并用子类型数组实现它?


I have the following abstract class

abstract class Vec2t<T : Number>(open var x: T, open var y: T)

implemented by

data class Vec2(override var x: Float, override var y: Float) : Vec2t<Float>(x, y)

So far, everything works just fine

Now, I'd like to do something similar for the matrices, this is at the moment my abstract class

abstract class Mat2t<T : Number>(open var value: Array<out Vec2t<T>>)

that should be implemented by

class Mat2(override var value: Array<Vec2>) : Mat2t<Float>(value)

But compiler complains on Array<Vec2>:

Error:(8, 32) Kotlin: Type of 'value' doesn't match the type of the overridden var-property 'public open var value: Array> defined in main.mat.Mat2t'

I was told:

  • I can't change the type of a var property when I override it (but actually I am not really changing it, I am overriding it with a subtype.. is it the same thing?)
  • mat2.value = object : Vec2t<Float>() { ... } would not be valid, which must not be the case for any subclass of Mat2t<Float>

How may I overcome these problems?

Is there a way to have an abstract generic class Mat2t with a generic array and implement it with a subtype array?


原文:https://stackoverflow.com/questions/40528739
更新时间:2024-04-02 21:04

最满意答案

没有任何ORDER BY不保证结果的顺序。

您的问题现在被严重截断,但原始版本提到您在使用nolocktablock时看到了不同的结果顺序。

这两个锁定选项都允许SQL Server使用分配顺序扫描,而不是按逻辑顺序沿着聚簇索引数据页读取(沿着链接列表的指针)。

这不应被视为保证订单处于聚簇索引顺序而不是高级扫描机制 ,或者例如并行性可以改变这一点。


Without any ORDER BY no order of results is guaranteed.

Your question is now heavily truncated but the original version mentioned that you saw different order of result when using nolock as well as tablock.

Both of these locking options allow SQL Server to use an allocation order scan rather than reading along the clustered index data pages in logical order (following pointers along the linked list).

That should not be taken as meaning that the order is guaranteed to be in clustered index order without that as the advanced scanning mechanism, or parallelism for example could both change this.

相关问答

更多
  • 没有功能差异,但最终没有WITH的语法将不起作用。 这已被弃用: select customer, zipcode from customers c (nolock) 所以你应该使用这种格式: select customer, zipcode from customers c with (nolock) 至少从SQL Server 2008开始不推荐使用WITH关键字作为表提示。搜索以下主题以获取Specifying table hints without using the WITH keywor ...
  • WITH(NOLOCK)相当于使用READ UNCOMMITED作为事务隔离级别。 因此,您可能会收到随后回滚的未提交的行的风险,即从未将其导入数据库的数据。 所以,虽然它可以防止读取被其他操作锁定,但却带来了风险。 在一个具有高交易率的银行业务应用程序中,它可能不是正在解决任何你想要解决的问题。 WITH (NOLOCK) is the equivalent of using READ UNCOMMITED as a transaction isolation level. So, you stand t ...
  • 是的,所以这里是我的博客中的条目: NOLOCK提示与将“隔离级别”设置为“未提交读取”的事务中包装查询基本相同。 这意味着查询并不在乎物件是否正在写入正在读取的行中 - 它会读取“脏”数据,并将其作为结果集的一部分返回。 原来,您可以使用.NET 2.0中引入的旧System.Transactions命名空间来完成整个“读取未提交”事务。 以下是一些示例代码: using (var txn = new TransactionScope( TransactionScopeOption.Require ...
  • 我不会解决READ UNCOMMITTED参数,只是你原来的问题。 是的,您需要在连接的每个表上WITH(NOLOCK) 。 不,你的查询是不一样的。 尝试这个练习。 开始事务并将一行插入到table1和table2中。 不要提交或回滚事务。 此时,您的第一个查询将成功返回并包含未提交的行; 您的第二个查询将不会返回,因为table2没有WITH(NOLOCK)提示。 I won't address the READ UNCOMMITTED argument, just your original ques ...
  • 区别在于你应该使用语法WITH (NOLOCK) (或WITH () )。 为什么? 不WITH已弃用。 从MSDN上的表提示 : 省略WITH关键字是不推荐的功能:此功能将在未来版本的Microsoft SQL Server中删除。 避免在新开发工作中使用此功能,并计划修改当前使用此功能的应用程序。 from table1 nolock根本不适用 - 这是一个别名。 例如: SELECT nolock.name FROM sys.objects nolock ORDER B ...
  • 没有任何ORDER BY不保证结果的顺序。 您的问题现在被严重截断,但原始版本提到您在使用nolock和tablock时看到了不同的结果顺序。 这两个锁定选项都允许SQL Server使用分配顺序扫描,而不是按逻辑顺序沿着聚簇索引数据页读取(沿着链接列表的指针)。 这不应被视为保证订单处于聚簇索引顺序而不是高级扫描机制 ,或者例如并行性可以改变这一点。 Without any ORDER BY no order of results is guaranteed. Your question is now h ...
  • FREETEXTTABLE不支持表提示。 如果您希望在整个过程中进行未提交的读取(这是NOLOCK为单个表实现的),请在T-SQL中设置事务隔离级别: SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; SELECT * FROM myTable AS FT_TBL FULL OUTER JOIN FREETEXTTABLE (myTable, fieldName, 'SRI') AS KEY_TBL ON FT_TBL.id = KEY_TBL ...
  • 不可以 。插入,更新和删除等数据修改操作受低级物理锁存器保护。 所有数据访问操作(包括无锁SELECT)都必须符合锁存协议。 其结果是任何读者都不会看到部分写入。 No. Data modification operations like inserts, updates and deletes are protected by low level physical Latches. All data access operations, including lock-free SELECT, are ob ...
  • 您的同事不正确, NOLOCK在上下文cftransaction之外并不是多余的。 如果使用SQL Server中的默认设置,则无论是否已明确键入,您执行的每个查询都将包含在事务中。 这称为“ 自动提交模式 ”。 Your co-worker in incorrect, NOLOCK is not redundant outside the context cftransaction. If you are using the default setting in SQL Server, every que ...
  • 经过几个小时的努力,我终于做到了。 如果有人需要它: WITH RESULTS AS( SELECT EVENTS.EMPID, CAST(DATEDIFF(d,0,EVENTS.EVENTIME) AS DATETIME) AS EVENTIME, COUNT(CAST(DATEDIFF(d,0,EVENTS.EVENTIME) AS DATETIME)) AS THIS_DAY FROM EVENTS INNER JOIN EMP ON EVENTS.EMPID = EMP.ID ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)