首页 \ 问答 \ 如何将null转换为Throwable super((Throwable)null);(how can null be casted to Throwable super((Throwable)null); [duplicate])

如何将null转换为Throwable super((Throwable)null);(how can null be casted to Throwable super((Throwable)null); [duplicate])

这个问题在这里已有答案:

这个问题只是让我理解这个概念。 如何将null转换为(Throwable)? null不是一个类吧? 这个问题很可愚蠢。

我知道:

public class SuperClass{
    int id = 0;
    public SuperClass(int id){
        this.id = id;
    }
}

public class SubClass extends SuperClass{
    public SubClass(int id) {
        super(id);
    }       
}

public class Tester{
    SubClass sub = new SubClass(1);
    SuperClass s = new SuperClass(2);
    SuperClass s1 = new SubClass(3);

    public Tester(){
        if(s1 instanceof SubClass){
            //true
            SubClass subClass = (SubClass) s1;
        }
    }       
}`

This question already has an answer here:

This question is just for me to understand this concept. How can null be casted to (Throwable)? null is not a class right? This question is propably stupid.

I know that:

public class SuperClass{
    int id = 0;
    public SuperClass(int id){
        this.id = id;
    }
}

public class SubClass extends SuperClass{
    public SubClass(int id) {
        super(id);
    }       
}

public class Tester{
    SubClass sub = new SubClass(1);
    SuperClass s = new SuperClass(2);
    SuperClass s1 = new SubClass(3);

    public Tester(){
        if(s1 instanceof SubClass){
            //true
            SubClass subClass = (SubClass) s1;
        }
    }       
}`

原文:https://stackoverflow.com/questions/36591777
更新时间:2024-02-13 06:02

最满意答案

我使用它的唯一方法是使用WhitespaceAnalyzer而不是StandardAnalyzer。 然后像这样使用TermQuery:

IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_36, new WhitespaceAnalyzer(Version.LUCENE_36))
            .setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
writer = new IndexWriter( directory, config);

然后搜索:

TopDocs docs = searcher.search(new TermQuery(new Term("uuid", uuid.toString())), 1);

WhitespaceAnalyzer阻止Lucene用连字符拆分UUID。 另一种选择可能是从UUID中消除破折号,但使用WhitespaceAnalyzer也可以用于我的目的。


The only way I got this to work is to use WhitespaceAnalyzer instead of StandardAnalyzer. Then using a TermQuery like so:

IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_36, new WhitespaceAnalyzer(Version.LUCENE_36))
            .setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
writer = new IndexWriter( directory, config);

Then searching:

TopDocs docs = searcher.search(new TermQuery(new Term("uuid", uuid.toString())), 1);

WhitespaceAnalyzer prevented Lucene from splitting apart the UUID by the hyphens. Another option could be to eliminate the dashes from the UUID, but using the WhitespaceAnalyzer works just as well for my purposes.

相关问答

更多
  • lucene怎么用[2022-07-03]

    Lucene是一个全文检索系统框架,开源的。 用起来比较方便,去Lucene的官网上下一个包并导入到你的工程中就可以调用包里面的类了。 一般的书里面介绍的版本都是1.4.3或者稍微高级一点的,不过现在lucene3.0正式发布,一些函数调用方法已经改变了,你可以下载一个版本低一点的Lucene比较适合学习~ 当然你直接从3.0入手的话网上资料也是非常丰富的~
  • 时间领域是问题。 似乎在我的文档中没有时间戳 编辑我的Elasticsearch数据源 将时间字段名称从@timestamp为update_date 我现在有数据点! time field was the problem. it seems there is no timestamp in my documents edited my Elasticsearch datasource changed 'Time field name' from @timestamp to update_date I hav ...
  • 我使用它的唯一方法是使用WhitespaceAnalyzer而不是StandardAnalyzer。 然后像这样使用TermQuery: IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_36, new WhitespaceAnalyzer(Version.LUCENE_36)) .setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND); write ...
  • 我不相信你可以创建一个scoredoc然后将它传递给searchAfter。 您需要使用先前搜索返回的ScoreDocs。 I don't believe you can create a scoredoc and then pass it to searchAfter. You need to use the ScoreDocs returned from a previous search.
  • 你应该尝试获取目录方法。 或者请检查您是否有任何我的知识,这个目录打开方法是以前的lucene版本。 请看 http://guntucomputerhacks.blogspot.com.au/2014/08/basic-indexing-and-searching-example.html FSDirectory objDirectory = FSDirectory.GetDirectory(pstrDatabase_path); Analyzer Analyzer ...
  • 我看到你正在使用cordova-plugin-uniquedeviceid包来获得uuid。 这是cordova-plugin-uniquedeviceid库文档告诉如何获取设备uuid的方式。 // Get UUID function onDeviceReady() { window.plugins.uniqueDeviceID.get(success, fail); } function success(uuid){ console.log(uuid); }; document.add ...
  • “上传”可能是您的Lucene索引中的一个令牌,其中令牌将是不可拆分的最小实体。 如果你想匹配像'Uplo'这样的部分单词,那么最好选择Lucene NGram Indexing 。 请注意,如果您选择NGram索引,则倒排索引的空间要求会更高。 'Upload' might be ONE Token in your Lucene index where a Token would be the smallest entity non splittable further. If you want to m ...
  • 您不需要打开自己的IndexReader; 只需创建SearcherManager(从您的IndexWriter)然后使用它的获取/释放,以获得搜索者/读者。 在使用编写器添加/删除文档后,您应该调用maybeReopen,然后在下次调用SearcherManager.acquire时,返回的搜索器将反映更改。 最好使用后台线程(即,不是执行搜索的线程)来索引文档并调用maybeReopen。 您不需要调用IndexWriter.commit来使更改可见 - 只有在您需要持久性时才调用它(即,所有更改都安全 ...
  • 我终于想出了一个解决方案,即明确指定用于ID查询的KeywordAnalyzer 。 找到它有点棘手,因为最初我使用Hibernate Search DSL代码来构建查询,但是使用专用分析器我只能使用Lucene Parser找到代码。 这是一个片段, QueryParser parser = new QueryParser(Version.LUCENE_31, "instanceId", new KeywordAnalyzer()); try { ...
  • 您可以使用邻近搜索来查找彼此相距一定距离的术语。 Lucene查询语法看起来像这个"jon skeet"~3 ,意思是在彼此的三个单词中找到“jon”和“skeet”。 使用这种语法,相对顺序无关紧要; “jon q.sibet”,“skeet,q.jon”和“jon skeet”都将匹配。 如果您有一个要作为单个标记处理的短语列表,则需要在分析仪中进行处理。 例如,您想将“近东”,“中东”和“远东”视为单独的代币。 你需要编写一个具有前瞻性的分析器,这样它就可以将这些短语看作是一个单词。 此分析器既可用于 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。