假设我们有下一个情况:
家长A:
class A{
public A(){}
public doSomething(){
System.out.println(this.getClass());
}
}
Run Code Online (Sandbox Code Playgroud)
带着孩子B级:
class B extends A{
public B(){}
public void doSomething(){
super.doSomething();
System.out.println(this.getClass());
}
}
Run Code Online (Sandbox Code Playgroud)
和主要课程:
class Main{
public static void main(String[] args){
A ab=new B();
ab.doSomething();
}
}
Run Code Online (Sandbox Code Playgroud)
当我执行此代码时,结果是
B
B
Run Code Online (Sandbox Code Playgroud)
为什么this在超类A中引用,B当引用是类型A 时返回为类?
出于检查空指针的习惯,我有时写道:
MyClass * c = someBasePtr ? dynamic_cast<MyClass*>(someBasePtr) : 0;
if (c) {...
Run Code Online (Sandbox Code Playgroud)
实际上,在传递给动态强制转换之前检查空指针,并检查返回.
然后我读了MSDN文档
通过dynamic_cast将空指针值转换为目标类型的空指针值.
然后我可以安全地删除?:构造.这个C++是可移植的吗?
这样新代码就可以了
MyClass * c = dynamic_cast<MyClass*>(someBasePtr);
if (c) {...
Run Code Online (Sandbox Code Playgroud)
当然假设someBasePtr是null或有效,即不是疯狂指向垃圾......
我正在尝试使用Matplotlib和Numpy,但这并不容易.
我正在做一个迷你项目,开始处理Matplotlib和Numpy,但我被困了......
这是代码:
# Modules
import datetime
import numpy as np
import matplotlib.finance as finance
import matplotlib.mlab as mlab
import matplotlib.pyplot as plot
# Define quote
startdate = datetime.date(2010,10,1)
today = enddate = datetime.date.today()
ticker = 'uso'
# Catch CSV
fh = finance.fetch_historical_yahoo(ticker, startdate, enddate)
# From CSV to REACARRAY
r = mlab.csv2rec(fh); fh.close()
# Order by Desc
r.sort()
### Methods Begin
def moving_average(x, n, type='simple'):
"""
compute an n period moving average.
type is 'simple' | 'exponential'
"""
x …Run Code Online (Sandbox Code Playgroud) 我正在使用ASP.NET MVC 3和Entity Framework code first CTP 5.我想知道是否可以添加未映射到表列的其他属性?
我有一个新闻类,它定义如下:
public class News : Entity
{
public int NewsId { get; set; }
public string Title { get; set; }
public string Body { get; set; }
public bool Active { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的数据库上下文类:
public class MyContext : DbContext
{
public DbSet<News> Newses { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在实体类中,我有一个定义为的属性:
public IList<RuleViolation> RuleViolations { get; set; }
Run Code Online (Sandbox Code Playgroud)
我还没有对这部分进行编码,但我希望在验证对象时将所有破坏的规则添加到此列表中.我得到的错误是:
One or more validation errors were detected during …Run Code Online (Sandbox Code Playgroud) asp.net asp.net-mvc entity-framework entity-framework-4 asp.net-mvc-3
通过外部配置文件,我的意思是除web.config之外的.config文件.我已经看到了有关如何在运行时编辑web.config的所有示例,但我想编辑configSource为appSettings引用的配置文件.我想只修改外部文件,我将处理应用程序回收.
理想情况下,我想使用内置类来处理编辑,但如果唯一的选项是手动文件打开/解析等,那么sobeit.
所有这一切背后的一般想法是在应用启动时查看的设置页面,用户设置他们的详细信息然后保存更改,然后真正的应用程序启动.快速轻松地安装app/configure页面,所以我想尽可能利用.config.
谢谢!
FOLLOWUP - 使用XmlDocument更改appSetting键值的快速代码段:
string path = Server.MapPath("~/my.config");
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNode node = doc.SelectSingleNode("/appSettings/add[@key='myKey']");
node.Attributes[1].Value = "myVal";
XmlTextWriter writer = new XmlTextWriter(path, null);
writer.Formatting = Formatting.Indented;
doc.WriteTo(writer);
writer.Flush();
writer.Close();
Run Code Online (Sandbox Code Playgroud) 我有一个变量${bean.name}如何将它传递给javascript var?我试过了 var name = "${bean.name}" , var name = ${bean.name}但它不起作用.
我的想法是把它放在一个隐藏的输入中,就像隐藏的一样 <input id="test" type="text" value"${bean.name}">
var name = document.getElementById("test").value;
Run Code Online (Sandbox Code Playgroud)
这不起作用或var name成为字符串"${bean.name}"
注意.我不能使用jstl
在Eclipse中,为什么缺少子类上显示的接口方法,而不是父类?
假设我有一个简单的界面:
public interface ISpeaks {
String talk();
}
Run Code Online (Sandbox Code Playgroud)
然后,我在一个扩展的类上实现了这个接口:
public abstract class Cat implements ISpeaks {
// forgot to implement talk()
}
public class Tiger extends Cat {
// also didn't implement talk()
}
Run Code Online (Sandbox Code Playgroud)
Eclipse抱怨Tiger缺少方法talk()(确切错误:) The type Tiger must implement the inherited abstract method ISpeaks.talk().我希望它告诉我Cat缺少talk(),因为Cat是明确实现接口的类.不是老虎.
这绝对是一个"呃?" 对我来说,因为我在Spring/Hibernate中,每当我向DAO接口添加一个方法时,每次数据库感知的测试用例都会出现这样的错误,这是一个缺少方法的错误 - 而不是单个错误模拟我的DAO的基本测试方法.
任何人都知道这是什么以及如何解决它?"OMG"
<p>After 32 years in its former location, this popular restaurant
and bar moved to the bottom of the Avalon Bay Luxury residential building
that's just a walk from Angel Stadium. Modern and welcoming, the expansive
space is where fans, locals and families gather for upscale twists on classic
American dishes. Burgers here have a decidedly fun flair like “The OMG�
that is a burger surely meant for sharing (with many)--it's so huge that it's
served on a 14-inch bun. …Run Code Online (Sandbox Code Playgroud) 除了屏幕类型(背光LCD,OLED,哑光,光面等......),什么配色方案在阳光直射下提供最大的可读性?
在谷歌搜索的一天,我无法找到很多.Kindle在灰色上使用黑色.我已经看到一些移动应用程序在黑色上使用浅灰色,声称具有良好的阳光可读性.随着移动应用程序的多样化,我感到惊讶的是,在简单的搜索距离内,这个主题并没有更多.
我甚至在油漆中制作了一堆测试样本,然后到外面翻转它们.今天外面大部分是阴天,所以它不是直射阳光,但是从那个快速的主观测试中,黑色白色是最好的白色黑色,黑色黄色和黑色浅灰色仍然很可读.
我想从文本文件中删除一些信息而不转移其所有记录.例如,给出了一个文本文件customers.txt.它有很多由#分隔符分隔的记录.每条记录包含以...分隔的字段;.像这样:1665;John;Smith给定客户ID,我想删除具有相应ID的客户.我可以在文件中找到记录的偏移量和长度,但不知道如何删除它.我必须重写整个文件吗?
注意:我正在使用带有g ++ 4.5和libst4的标准C++.
asp.net ×2
c++ ×2
java ×2
asp.net-mvc ×1
c# ×1
color-scheme ×1
dynamic-cast ×1
eclipse ×1
el ×1
encoding ×1
file-io ×1
html ×1
inheritance ×1
interface ×1
javascript ×1
jsp ×1
matplotlib ×1
null ×1
numpy ×1
php ×1
python ×1
readability ×1
std ×1
stockquotes ×1
this ×1
utf-8 ×1