我看到,在JSF中,大多数映射到HTML标签的标准组件,例如<h:commandButton/>,具有属性class和styleClass.但无论我使用哪一个,都会class在标记中呈现为属性.
那么为什么有两个具有相同目的的属性呢?
我读过Joshua Bloch的精彩"有效Java".但书中的一个例子对我来说还不清楚.它来自关于泛型的章节,具体项目是"第28项:使用有界通配符来增加API灵活性".
在这个项目中,它展示了如何使用有界类型参数和有界通配符类型编写从集合中选择最大元素的算法的最通用和防弹(在类型系统的角度)版本.
编写的静态方法的最终签名如下所示:
public static <T extends Comparable<? super T>> T max(List<? extends T> list)
Run Code Online (Sandbox Code Playgroud)
它Collections#max与标准库中的函数大致相同.
public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll)
Run Code Online (Sandbox Code Playgroud)
我理解为什么我们需要在T extends Comparable<? super T>类型约束中使用有界通配符,但它在参数的类型中是否真的有必要?在我看来,这将是相同的,如果我们只留下List<T>或者Collection<T>,是不是?我的意思是这样的:
public static <T extends Comparable<? super T>> T wrongMin(Collection<T> xs)
Run Code Online (Sandbox Code Playgroud)
我写了以下使用两个签名的愚蠢示例,并没有看到任何不同之处:
public class Algorithms {
public static class ColoredPoint extends Point {
public final Color color;
public ColoredPoint(int x, int y, Color color) { …Run Code Online (Sandbox Code Playgroud) 我将尝试在以下简化示例中说明我的问题:
public class DataHolder<T> {
private final T myValue;
public DataHolder(T value) {
myValue = value;
}
public T get() {
return myValue;
}
// Won't compile
public <R> DataHolder<R super T> firstNotNull(DataHolder<? extends R> other) {
return new DataHolder<R>(myValue != null ? myValue : other.myValue); }
public static <R> DataHolder<R> selectFirstNotNull(DataHolder<? extends R> first,
DataHolder<? extends R> second) {
return new DataHolder<R>(first.myValue != null ? first.myValue : second.myValue);
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,我想写泛型方法firstNotNull返回DataHolder的类型参数的共同参数化父T的this和 …
据我所知,像Mercurial这样的分布式修订控制系统的主要优点之一就是你不应该担心在你的超级重要主仓库中破坏某些东西(很多其他开发人员都会使用它),并且你所做的就是所有的工作和研究在你的个人远程克隆中,直到你明白一切都稳定,你可以推动你的工作.因此我得到了一个问题:如果有可能不会推回所有的更改历史记录(您为自己制作了几个修订版),但只有一个实际上是在您的回购和当前状态之间的差异.
一个例子:
hg init master-repo; cd master-repo
echo -e 'Important file\nWith Bug!' > file
hg commit -A -m "initial commit"
cd ..; hg clone master-repo hotfix-repo; cd hotfix-repo
echo "fix1" >> file
hg commit -m "first attempt to fix bug"
echo "fix2" >> file
hg commit -m 'Fixed it!'
Run Code Online (Sandbox Code Playgroud)
现在(可能在拉动并合并最新的master-repo'更改之后)我想只推回一个包含我在没有本地提交历史记录的情况下完成的所有更改的变更集.一种可能的解决方案是再创建一个克隆,然后在两个克隆之间使用diff/patch从第一个克隆中提取/应用更改,并在第二个repo中一次性提交所有更改.然后像正常情况一样按下.但是有可能只使用mercurial命令吗?
谢谢你!
最近我设置了我的XFCE终端,使用这个准备好的配置使用Solarized的完美调色板 .
一切正常(虽然午夜指挥官的颜色让我哭了)但有一件事对我很好奇:
为什么xfce终端设置中的颜色代码包含12个十六进制数字而不是6个?像这样一个:
ColorPalette8=#d3d3d7d7cfcf
Run Code Online (Sandbox Code Playgroud)
这是什么意思?它是如何与官方页面上指定的颜色代码相关的
我正在寻找一些XSLT样式表,可以处理我的xml文档的正确缩进,并在http://www.printk.net/~bds/indent.html找到了非常好的.
希望作者不会因为这样的引用而责怪我:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="ISO-8859-1"/>
<xsl:param name="indent-increment" select="' '"/>
<xsl:template name="newline">
<xsl:text disable-output-escaping="yes">
</xsl:text>
</xsl:template>
<xsl:template match="comment() | processing-instruction()">
<xsl:param name="indent" select="''"/>
<xsl:call-template name="newline"/>
<xsl:value-of select="$indent"/>
<xsl:copy />
</xsl:template>
<xsl:template match="text()">
<xsl:param name="indent" select="''"/>
<xsl:call-template name="newline"/>
<xsl:value-of select="$indent"/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>
<xsl:template match="text()[normalize-space(.)='']"/>
<xsl:template match="*">
<xsl:param name="indent" select="''"/>
<xsl:call-template name="newline"/>
<xsl:value-of select="$indent"/>
<xsl:choose>
<xsl:when test="count(child::*) > 0">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="*|text()">
<xsl:with-param name="indent" select="concat ($indent, $indent-increment)"/>
</xsl:apply-templates>
<xsl:call-template name="newline"/>
<xsl:value-of select="$indent"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise> …Run Code Online (Sandbox Code Playgroud) 假设ArticleVersion我的项目中有一个模型,定义为:
class ArticleVersion(models.Model):
article = models.ForeignKey(Article)
version = models.PositiveIntegerField()
content = models.TextField()
created = models.DateTimeField(auto_now_add=True)
media_type = models.ForeignKey(MediaType)
author = models.ForeignKey(User, null=True)
Run Code Online (Sandbox Code Playgroud)
当用户填写此模型的表单时,我会检查表单中的版本内容是否不同,如果是,我会创建新版本.实际上现在它看起来像这样
if self.old_content != updated_version.content:
# create new version if content is different
updated_version = self.article.articleversion_set.create(
article=self.article,
version=self.article.latest_version.version + 1,
content=updated_version.content,
media_type=updated_version.media_type,
author=updated_version.author
)
Run Code Online (Sandbox Code Playgroud)
但是如果我在模型中添加更多字段,那就太冗长了.我想知道有没有办法更简洁地在Django中做这些事情?