我想months
使用Arrays.sort
方法按长度对数组中的String元素进行排序.我在这里被告知,可以使用lambda表达式而不是创建实现Comparator的新类.是否完全相同,但它不起作用.
import java.util.Arrays;
import java.util.Comparator;
public class MainClass {
public static void main(String[] args)
{
String[] months = {"January","February","March","April","May","June","July","August","September","October","December"};
System.out.println(Arrays.toString(months)); //printing before
//neither this works:
Arrays.sort(months,
(a, b) -> Integer.signum(a.length() - b.length())
);
//nor this:
Arrays.sort(months,
(String a, String b) -> { return Integer.signum(a.length() - b.length()) };
);
System.out.println(Arrays.toString(months)); //printing after
}
}
Run Code Online (Sandbox Code Playgroud) 我有3个项目:服务器,客户端和共享.在Commons中创建头和源对不会导致任何问题,我可以从服务器和客户端自由访问这些功能.
然而,由于某些原因使中附加源/头文件服务器或客户端的项目总是会引起multiple definition of (...)
和first defined here
错误.
例:
commands.h(在Client项目的根目录中)
#ifndef COMMANDS_H_
#define COMMANDS_H_
#include "commands.c"
void f123();
#endif /* COMMANDS_H_ */
Run Code Online (Sandbox Code Playgroud)
commands.c(在Client项目的根目录中)
void f123(){
}
Run Code Online (Sandbox Code Playgroud)
main.c(在Client项目的根目录中)
#include "commands.h"
int main(int argc, char** argv){
}
Run Code Online (Sandbox Code Playgroud)
错误:
make: *** [Client] Error 1 Client
first defined here Client
multiple definition of `f123' commands.c
Run Code Online (Sandbox Code Playgroud)
清洁,重建索引,重建项目没有帮助.也没有重新启动计算机.
考虑这个例子:
async Task Foo()
{
button.Text = "This is the UI context!";
await BarA();
button.Text = "This is still the UI context!";
await BarB();
button.Text = "Oh no!"; // exception (?)
}
async Task BarA()
{
await Calculations();
}
async Task BarB()
{
await Calculations().ConfigureAwait(false);
}
Run Code Online (Sandbox Code Playgroud)
如何await BarB()
在不读取async Task BarB()
函数体的情况下更改上下文?我是否真的需要确切知道异步函数是否ConfigureAwait(false)
在任何时候调用?或者这个例子可能是错误的并且没有例外?
我正在做这个WPF教程,由于某种原因,我在向SlidersToColorConverter
资源添加自定义类时遇到错误.
StackOverflow上的某个人以同样的方式完成它.
MainWindow.xaml:
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication2"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:SlidersToColorConverter x:Key="whyareyounotworking"/>
</Window.Resources>
</Window>
Run Code Online (Sandbox Code Playgroud)
SlidersToColorConverter.cs:
namespace WpfApplication2
{
class SlidersToColorConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
double red = (double)values[0];
double green = (double)values[1];
double blue = (double)values[2];
return new SolidColorBrush(Color.FromArgb(255, (byte)red, (byte)green, (byte)blue));
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
Run Code Online (Sandbox Code Playgroud)
错误列表:
The name …
Run Code Online (Sandbox Code Playgroud) TestContext
这些是在class 及其各自的定义中定义的(未弃用的)目录。
DeploymentDirectory
ResultsDirectory
TestResultsDirectory
TestRunDirectory
TestRunResultsDirectory
我发现他们很模棱两可。每个目录都有一些可靠的示例用法吗?例如,如果我要测试文件 I/O,如果我想创建临时lorem ipsum文件,那么其中任何一个都可以吗?
试图理解数据绑定,这完全看起来像是一个菜鸟错误,但我不知道为什么会发生这种情况。
CS
namespace MuhProgram
{
public partial class MainWindow : Window
{
public string foobar
{
get { return "loremipsum"; }
}
public MainWindow()
{
InitializeComponent();
}
}
}
Run Code Online (Sandbox Code Playgroud)
XAML:
<Window x:Class="MuhProgram.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MuhProgram"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:MainWindow x:Key="classMainWindow"/>
</Window.Resources>
<Grid>
<Label Content="{Binding Source={StaticResource classMainWindow}, Path=foobar}"></Label>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
调试器指向带有 StackOverflowException 的方法InitializeComponent()
调用MainWindow()
。
我也尝试在网格中设置DataContext
属性"{StaticResource classMainWindow}"
,但效果是相同的。
Apple会指定这个吗?应该在PES数据包有效负载中放入多少个访问单元?
另外,我想知道PES包中存在哪些前缀起始码(如果有的话).我假设访问单元中第一个NAL单元之前的那个是无用的,不能放.对?
我想知道它是如何在HLS中专门完成的 - 不一定是任何其他MPEG-2 TS应用程序.
我正在实现一个通用字典.我想要TKey
成为一个结构或类.如果它是一个结构,我想按值比较键,否则通过引用.
我不能既不使用Object.Equals
(仅适用于结构),也不能Object.ReferenceEquals
(仅适用于引用类型).那么我用什么方法来测试相等性呢?
==
运算符可能会解决这个问题但我不能在没有为key(where TKey : ...
)指定任何约束的情况下使用它.我应该声明什么接口?
考虑这个属性列表:
(defvar *some-variable* (list :foo "fooval" :bar "barval"))
Run Code Online (Sandbox Code Playgroud)
这个简单的电话:
(getf *some-variable* :foo)
Run Code Online (Sandbox Code Playgroud)
收益率"fooval"
如预期.我定义了一个宏应该做同样的事情,除了我可以传递任何属性的名称来检索:
(defmacro my-macro (property-name)
`(getf *some-variable* :,property-name))
Run Code Online (Sandbox Code Playgroud)
不幸的是,这样称呼它:
(my-macro 'foo)
Run Code Online (Sandbox Code Playgroud)
结果FOO
.为什么?
c# ×5
wpf ×2
xaml ×2
.net ×1
arrays ×1
async-await ×1
c ×1
clisp ×1
common-lisp ×1
data-binding ×1
definition ×1
dictionary ×1
eclipse ×1
equality ×1
generics ×1
h.264 ×1
include ×1
java ×1
java-8 ×1
lambda ×1
lisp ×1
macros ×1
mpeg2-ts ×1
reference ×1
resources ×1
sorting ×1
testcontext ×1
testing ×1
ui-thread ×1
unit-testing ×1