我读到某处接口可以有成员变量.
仅静态最终常量,可以在实现接口的类中无限制地使用它们.在另一个爪子上,这些不合格的名称污染了命名空间.您可以使用它们,因为资格是可选的,所以它们来自哪里并不明显.
我不太明白他们的意思?有帮助吗?
我正在尝试使用以下代码下载zip文件:
o = urllib2.build_opener( urllib2.HTTPCookieProcessor() )
#login
p = urllib.urlencode( { usernameField: usernameVal, passField: passVal } )
f = o.open(authUrl, p )
data = f.read()
print data
f.close()
#download file
f = o.open(remoteFileUrl)
localFile = open(localFile, "wb")
localFile.write(f.read())
f.close()
Run Code Online (Sandbox Code Playgroud)
我得到一些二进制数据,但我"下载"的文件的大小太小,不是一个有效的zip文件.我没有正确检索zip文件吗?HTTP响应头f = o.open(remoteFileUrl)如下所示.我不知道是否需要特殊处理来处理这个响应:
HTTP/1.1 200 OK服务器:
Apache-Coyote/1.1 Pragma:private
Cache-Control:must-revalidate
Expires:Tue,1997年12月31日23:59:59 GMT
Content-Disposition:inline;
文件名= "files.zip";
内容类型:application/zip
Transfer-Encoding:chunked
我想要做的是为我的一些模型设置一个基类,它具有一些默认的activerecord行为:
class Option < ActiveRecord::Base
has_many :products
def some_method
#stuff
end
#etc..etc..
end
class ColorOption < Option
#stuff...
end
class FabricOption < Option
#stuff...
end
Run Code Online (Sandbox Code Playgroud)
但是,我希望每个ColorOption和FabricOption都在他们自己的表中.我不想使用STI或为基类"Option"设置表.我实现这一点的唯一方法是使用一些非继承元编程魔法.但我想知道是否有办法告诉AR基类不需要表.它只是用于额外行为,并像往常一样将其他子类放在自己的表中.
谢谢,克雷格
真的只是一般问题吗?
假设我正在制作游戏,并在Blender制作了角色模型.我如何在Java中使用此模型?
我会以某种方式导入它吗?
谢谢.
我以前有这样的模型:
class AssemblyAnnotation(models.Model):
assembly = models.ForeignKey(Assembly)
type = models.ForeignKey(AssemblyAnnotationType)
...
def clean(self):
from django.core.exceptions import ValidationError
if not self.type.can_annotate_aliases and self.assembly.alias_of_id is not None:
raise ValidationError('The selected annotation type cannot be applied to this assembly.')
Run Code Online (Sandbox Code Playgroud)
结果是,新的AssemblyAnnotation(通过内联附加)只能为其type属性提供值的子集,具体取决于父程序集.
这很有效.
现在,是时候将这些注释应用于略有不同的其他对象:
class ObjectAnnotation(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey()
type = models.ForeignKey(AssemblyAnnotationType)
...
def clean(self):
from django.core.exceptions import ValidationError
if self.content_type == ContentType.objects.get_for_model(Assembly):
if not self.type.can_annotate_aliases and self.content_object.alias_of_id is not None:
raise ValidationError('The selected annotation type cannot be applied to …Run Code Online (Sandbox Code Playgroud) 我有以下代码将用户草图数据保存到文件中...
//Auto Save the sketch
NSString *filename = [NSString stringWithFormat:@"%@.png", sketchID];
CGImageRef imageRef = CGBitmapContextCreateImage(paintView.canvas.mBitmapContext);
UIImage* image = [[UIImage alloc] initWithCGImage:imageRef];
NSData* imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:filename atomically:YES];
CGImageRelease(imageRef);
[image release];
Run Code Online (Sandbox Code Playgroud)
这SketchID是一个唯一的字母数字值,因此我保存的文件名的示例是"p1.png".我用来读取文件的代码是......
//Load the sketch where the user left off, if there is one
if(fileName != nil)
{
UIImage* image = [UIImage imageWithContentsOfFile:fileName];
if(image != nil)
{
.
.
Run Code Online (Sandbox Code Playgroud)
在模拟器上运行时,此代码似乎工作正常,但是当我在设备上运行它时,无法加载图像.我是iOS开发的新手,我还在学习如何存储文件.我的问题是......
writeToFile:方法时,"p1.png"应该正常工作吗?那imageWithContentsOfFile:方法怎么样?非常感谢您的帮助!
使用Rails 3开始一个新的Web应用程序.我仍然是Web开发的新手,并且非常喜欢在Ruby 1.8.7和Rails 2.3.5中工作时可用的所有Internet资源.有关在我的新项目中使用Ruby 1.9.2的任何建议吗?
我正在尝试记录HttpServletRequest属性集合的内容.我需要在servlet首次启动时执行此操作,并在servlet完成之前再次执行此操作.我这样做是为了了解一个狡猾且维护不良的servlet.因为我需要尽可能少的影响,servlet过滤器不是一个选项.
所以这就是问题所在.当servlet启动时,我将遍历HttpServletRequest.getAttributeNames()返回的枚举.但是,当我想再次遍历它时,getAttributeNames().hasMoreElements()返回"false"!我找不到任何"重置"枚举的方法.更糟糕的是,即使我使用HttpServletRequest.setAttribute()向集合添加属性,当我调用getAttributeNames().hasMoreElements()时,我仍然得到"false"的结果.
这真的有可能吗?难道真的没有办法不止一次遍历属性名称吗?
根据要求,这是我的代码.这很简单 - 不要以为我做任何有趣的事情.
/**
*
* Returns the contents of the Attributes collection, formatted for the InterfaceTracker loglines
*
*/
@SuppressWarnings("unchecked")
public static String getAttributes(HttpServletRequest request) {
try {
StringBuilder toLog = new StringBuilder();
Enumeration attributeNames = request.getAttributeNames();
while(attributeNames.hasMoreElements()) {
String current = (String) attributeNames.nextElement();
toLog.append(current + "=" + request.getAttribute(current));
if(attributeNames.hasMoreElements()) {
toLog.append(", ");
}
}
return "TRACKER_ATTRIBUTES={"+ toLog.toString() + "}";
}
catch (Exception ex) {
return "TRACKER_ATTRIBUTES={" + InterfaceTrackerValues.DATA_UNKNOWN_EXCEPTION_THROWN + "}";
}
}
Run Code Online (Sandbox Code Playgroud) 原型模式的目标是通过降低创建成本来克隆对象.这是一个例子:
class Complex {
int[] nums = {1,2,3,4,5};
public Complex clone() {
return new Complex();//this line create a new object, so is it violate the objective of prototype ?//
}
}
class Test2 {
Complex c1 = new Complex();
Complex makeCopy() {
return (Complex)c1.clone();// Is it actually create a new object ? based on the clone method in Complex class? //
}
public static void main(String[] args) {
Test2 tp = new Test2();
Complex c2 = tp.makeCopy();
}
}
Run Code Online (Sandbox Code Playgroud)
我认为这是深刻的复制.所以,有人可以帮我解决这个问题吗?
java ×3
activerecord ×1
attributes ×1
blender ×1
cocoa-touch ×1
django ×1
django-admin ×1
enumeration ×1
enumerator ×1
graphics ×1
icons ×1
interface ×1
ios ×1
models ×1
objective-c ×1
python ×1
ruby ×1
ruby-1.9 ×1
servlets ×1
variables ×1
vb.net ×1