最近分配的变量在下一行中丢失其值

发布于 2024-12-18 10:15:30 字数 1077 浏览 2 评论 0原文

我正在 Liferay Developer Studio(即 Eclipse)中创建一个 Liferay portlet,并发现了一个非常非常奇怪的行为。

在一个 JSP 中,每次设置某个特定变量时,该变量的值都会在下一行中更改为 null。这太奇怪了,我觉得我应该对其进行截屏 - 它位于 这个 YouTube 视频中

AnoterFieldComparator 类从 Liferay 扩展了 OrderByComparator,如下所示。这个问题也发生在 OrderByComparator 子类上,尽管这对我来说没有意义。

public class AnoterFieldComparator extends OrderByComparator {
    @Override
    public int compare(Object o1, Object o2) {
        Example example1 = (Example)o1;
        Example example2 = (Example)o2; 
        return Integer.parseInt(""+(example1.getAnotherField() - example2.getAnotherField()));
    }
}

(是的,有一个拼写错误。这只是一个实验:))

可以在此处查看该项目< /a> 和 此处。我知道这个问题写得不太好,但我很惊讶,通常只有新手才会谈论这种行为,而且大多数时候他们都是错的。

I am creating a Liferay portlet in Liferay Developer Studio (which is Eclipse) and found a very, very strange behavior.

In one JSP, every time some specific variable is set, its variable has its value changed to null in the next line. This is so strange that I felt that I should make a screencast of it - and it is in this YouTube video.

The class AnoterFieldComparator extends OrderByComparator from Liferay, as seen below. This problem just happened to OrderByComparator subclasses as well, although this makes no sense to me.

public class AnoterFieldComparator extends OrderByComparator {
    @Override
    public int compare(Object o1, Object o2) {
        Example example1 = (Example)o1;
        Example example2 = (Example)o2; 
        return Integer.parseInt(""+(example1.getAnotherField() - example2.getAnotherField()));
    }
}

(Yes, there is a typo. It was just an experiment :) )

The project can be seen here and here. I know the question is not that well written, but I am pretty amazed, usually only novices talk about this kind of behavior, and they are wrong most of the time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨小沫ゞ 2024-12-25 10:15:30

AnoterFieldComparator(或其超类)的 toString 方法是什么?

屏幕截图中的值列不会变为 null,只是下面的框是此类的字符串表示形式,在视频末尾,您仍然可以在比较器的右侧看到类和对象 ID,因此变量不为 null,只是 to string 方法返回 null (0x0) 或字符串“null”。

What is the toString method of AnoterFieldComparator ( or its super class )?

The value column in you screen cast does not go to null just the box down below which is the string representation of this class, at the end of the video you can still see to the right of comparitor the class and the object id, so the variable is not null just the to string method either returned null (0x0) or the string "null".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文