- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用传入的参数创建一个新对象,然后使用该新对象放置在下面列出的 setCarColor 方法中。但是我的构造函数中的 setCarColor 为我的 clv 变量提供了错误。它说“找不到符号”。 clv 是 CarColor 类中的变量。我不确定是否是因为传入的参数(rdIn,grnIn,bluIn)是整数还是什么?请问有人有什么想法吗?
最诚挚的问候,
public abstract class Vehicle
{
private String shapeId;
CarColor carColor;//CarColor data member from the ColorValue.java class
public Shape(String bodyid, int rd, int grn, int ble)
{
CarColor clv = new CarColor(rdIn, grnIn, bluIn);
setCarColor(clv(rd, grn, ble));// <---error here
}
private CarColor getCarColor()
{
return carColor;
}
private void setCarColor(int redIn, int blueIn, int greenIn)
{
if (redIn == 0 || blueIn == 0 || greenIn == 0 )
{
System.out.println("The value entered in is null. Please try again ");
System.exit(-1);
}
}
最佳答案
这条线几乎很好:
ColorValue clv = new ColorValue(rdIn, grnIn, bluIn);
...虽然它没有填充colorValue
字段,这正是您所期望的,并且您实际上没有rdIn
、grnIn
和 bluIn
变量。您是指 rd
、grn
、ble
吗? (顺便说一句,如果您不使用这样的缩写名称,这会有所帮助。)
但是这条线有两种断裂方式:
setColorValue(clv(rd, grn, ble));
首先,它尝试调用一个名为 clv
的方法。你没有这样的方法。您有一个名为 clv
的变量,但您不“调用”变量。
第二个问题是,如果你真的是这个意思:
setColorValue(clv);
那么您将使用不正确的参数 - setColorValue
没有一个 ColorValue
类型的参数,它具有三个参数,全部为 int
>s.
不幸的是,目前尚不清楚您尝试做什么,因此很难为您提供建议。 也许你的意思是这样的:
public abstract class Geometry
{
private String shapeId;
private ColorValue colorValue;
public Shape(String shapeId, int red, int green, int blue)
{
this.shapeId = shapeId;
setColorValue(red, green, blue);
}
public ColorValue getColorValue()
{
return colorValue;
}
// Note the consistent order of the parameters - always red, green, blue.
public void setColorValue(int red, int green, blue)
{
// Don't use System.exit() in the middle of a method! An exception
// is the idiomatic way of reporting bad arguments.
if (red == 0 || blue == 0 || green == 0)
{
throw new IllegalArgumentException("red green and blue must be non-zero");
}
colorValue = new ColorValue(red, green, blue);
}
}
关于java - 在 Java 中创建新对象并将其传递给 setMethod 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9710988/
最近几天我一直在努力学习类和对象,我意识到在构造函数中使用“this.set”和“set”并没有明显的区别。澄清 public Movie(String title,String director,
本文整理了Java中ij.plugin.ZProjector.setMethod()方法的一些代码示例,展示了ZProjector.setMethod()的具体用法。这些代码示例主要来源于Github
我有兴趣为泛型函数设置新方法。例如,假设我有一个新类(class)(例如 coolClass)。我可以编写一个包装器来计算该类的 log10 并使用以下代码轻松设置该方法: setMethod("Ma
本文整理了Java中java.util.zip.ZipOutputStream.setMethod()方法的一些代码示例,展示了ZipOutputStream.setMethod()的具体用法。这些代
本文整理了Java中java.util.zip.ZipEntry.setMethod()方法的一些代码示例,展示了ZipEntry.setMethod()的具体用法。这些代码示例主要来源于Github
为标题道歉,不知道如何表达这个问题。 如果我想创建 setMethod在一个类(class)上如何区分mat[i,]的类似情况和 mat[i] ? 我知道我可以使用的前者: setMethod("["
题 在 r 中编程时与 s4 OOP系统,何时必须使用 setReplaceMethod ? 我看不出和 setMethod 有什么区别添加时 setReplaceMethod function (
我尝试使用传入的参数创建一个新对象,然后使用该新对象放置在下面列出的 setCarColor 方法中。但是我的构造函数中的 setCarColor 为我的 clv 变量提供了错误。它说“找不到符号”。
我正在尝试创建一个类Tax,它使用扫描仪变量从用户获取工资和税率,并使用用户的输入给出税后工资。 我收到的错误是 set-method 不能用于使用扫描仪变量。请提出解决方案。 代码如下:- pack
浏览 System.Linq.Expressions 的 .NET 核心源代码,我发现以下代码位于 here : MethodInfo mi = property.GetGetMethod(true)
本文整理了Java中org.apache.tools.zip.ZipOutputStream.setMethod()方法的一些代码示例,展示了ZipOutputStream.setMethod()的具
本文整理了Java中de.schlichtherle.truezip.zip.ZipEntry.setMethod()方法的一些代码示例,展示了ZipEntry.setMethod()的具体用法。这些
基本上,当 setMethod 或 (setGeneric) 中有很多参数时,它的运行速度会非常慢。 这是一个基本示例: setClassUnion(name = "mNumeric", member
所以,PropertyInfo 有一个 GetSetMethod 方法,它返回这个属性的 setter 方法。它还有一个 SetMethod 属性(据我所知)。 我问这个是因为如果属性不是公共(pub
经过几个小时的教程和谷歌搜索,我知道当我们在头文件中定义一个属性时,编译器会自动生成 setter 和 getter,这里是一个例子: “example.h” @property(strong,non
本文整理了Java中org.mozilla.zest.core.v1.ZestRequest.setMethod()方法的一些代码示例,展示了ZestRequest.setMethod()的具体用法。
我正在使用 setMethod 来覆盖不同类的对象的“摘要”函数。 最初,我使用了这种方法: setMethod('summary', "class_1", function(o
本文整理了Java中org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.setMethod()方法的一些代码示例,展示了Z
本文整理了Java中org.apache.commons.compress.archivers.zip.ZipArchiveEntry.setMethod()方法的一些代码示例,展示了ZipArchi
我有一些现有代码可以创建 Epub 2 格式的 zip 文件,它可以正常工作。 在尝试更新我的代码以支持 Epub 3 格式时,我想我会尝试使用 Java NIO Zip 文件系统而不是 java.u
我是一名优秀的程序员,十分优秀!