我有一个Color看起来像这样的基类.该类被设计为不可变的,因此结果具有final修饰符且没有setter:
public class Color
{
public static Color BLACK = new Color(0, 0, 0);
public static Color RED = new Color(255, 0, 0);
//...
public static Color WHITE = new Color(255, 255, 255);
protected final int _r;
protected final int _g;
protected final int _b;
public Color(int r, int b, int g)
{
_r = normalize(r);
_g = normalize(g);
_b = normalize(b);
}
protected Color()
{
}
protected int normalize(int val)
{
return val & 0xFF; …Run Code Online (Sandbox Code Playgroud) 我正在使用Damian Conway的"由内而外"的对象,如他所描述的那本精彩的书Perl Best Practices,用于在我的客户端构建面向对象的安全系统接口.我想在我的模块中使用内部帮助器方法,我通常将其指定为"_some_method".但是,这似乎打破了封装,因为它们可以通过包名直接调用.有没有办法让这些方法真正私密?举个例子,
use SOD::MyOOInterface;
my $instance1 = SOD::MyOOInterface->new();
$instance1->_some_method; #this produces an error:
SOD::MyOOInterface::_some_method; # this results in a
# successful method call
Run Code Online (Sandbox Code Playgroud)
显然我不希望_some_method的直接调用成功.有什么方法可以保证吗?
我想通过Java界面调用浏览器(例如Internet Explorer/Firefox/Google Chrome/Opera).此外,我需要传递一些Web链接到这个Java进程.怎么做到这一点?
如何在不更新其他对象流的情况下放置对象,但是指定相对于父对象的坐标?
澄清,
position: relative; top: -30px; left: 600px;更新以下对象的流程,
position: absolute; top: -30px; left: 600px;不更新流程但是相对定位.
我不需要更新流程,而是指定相对定位.我也可以使用Javascript解决方案.
编辑
我想一个更好的例子是:我有一个文档,我现在想放置一个<p>显示在现有文档上而不改变流程(想想水印).我还有一些特定的<div class ='abc'>,据我所知,我想将新的<p>放在坐标(600,-30)处.
我正在为Mac编写应用程序.我需要一些从字符串生成哈希的代码.我需要创建这些哈希:
我怎样才能做到这一点?谢谢.
因为我想使用libpcap和一个小型C程序进行一些测试,所以我试图将结构从main()传递给got_packet()。阅读libpcap教程后,我发现了这一点:
pcap_loop()的原型如下:
int pcap_loop(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
Run Code Online (Sandbox Code Playgroud)
最后一个参数在某些应用程序中很有用,但是很多时候只是将其设置为NULL。假设除了pcap_loop()发送的参数外,我们还有自己希望发送给回调函数的参数。这就是我们要做的。显然,您必须强制转换为u_char指针,以确保结果正确到达该指针。稍后我们将看到,pcap利用一些非常有趣的方式以u_char指针的形式传递信息。
因此,据此,可以使用pcap_loop()的参数编号4在got_packet()中发送结构。但是尝试之后,我得到了一个错误。
这是我的(错误的)代码:
int main(int argc, char **argv)
{
/* some line of code, not important */
/* def. of the structure: */
typedef struct _configuration Configuration;
struct _configuration {
int id;
char title[255];
};
/* init. of the structure: */
Configuration conf[2] = {
{0, "foo"},
{1, "bar"}};
/* use pcap_loop with got_packet callback: */
pcap_loop(handle, num_packets, got_packet, &conf);
}
void got_packet(u_char *args, const struct pcap_pkthdr …Run Code Online (Sandbox Code Playgroud) 如何在WPF TextBox 上设置正则表达式?我希望文本框以某种预定义的格式接受输入.可能吗?
我试过<input type="file" value="path..." />但不工作.
怎么修?
当我点击TVP时,我没有得到像'ALTER TO'这样的选项